aspose file tools*
The moose likes JDBC and the fly likes Writing to MySql Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Writing to MySql Database" Watch "Writing to MySql Database" New topic

Writing to MySql Database

Reuben Fields

Joined: Apr 05, 2005
Posts: 15
Hello again!

Thanks for all your help in the last topic, i got Tomcat setup ok!

I could really use your help on this one guys!

My problem is how to write to the database! I have a schema called broadband and my table that i am trying to write to is called member.

I have the following code:

String strUrl = "jdbc:mysql://localhost/broadband";
Connection conn=DriverManager.getConnection (strUrl, "root", "321321");

Statement stmt=conn.createStatement();
String pass = request.getParameter("pass");
String name = request.getParameter("name");

String sqlstr = "INSERT INTO member VALUES ('" + pass + "','" + name + "')";




Does this look right to you?
Then i created a form in the same jsp page:

<form name="form1" action="" method=post>
<input type="text" name="name" size="10" maxlength="25">
<input type="text" name="password" size="10" maxlength="25">

Do i need to put something in the action part of the form? And if so what else do i need to? Do i need to create another JSp file?
[ April 15, 2005: Message edited by: Bear Bibeault ]
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Hi Reuben,

Wow, that is a lot of logic to be putting into a jsp page... Have you considered putting the database statements into a servlet and then forwarding back to the jsp page?

anyway, as far as you code, you still need to put in an action. Just point the action back at the jsp page you are writing.

<form name="form1" action="myJsp.jsp" method=post>

Also, you may want to use a password field for the password instead of text... otherwise, it looks correct at first glance. Try deploying it and let me know if you et any errors.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Reuben Fields

Joined: Apr 05, 2005
Posts: 15

Does anyone know what is the exact name of the driver that i need for this, i think i goes in the web-inf folder aswell doesnt it?

Or is it this line that i need?


And if so what driver do i need for this?
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281

java amateur
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61761

This would be more appropriate in the JDBC forum.

Also changed the topic title to better suit subject matter.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Reuben Fields

Joined: Apr 05, 2005
Posts: 15
Would both



work with this driver?
I agree. Here's the link:
subject: Writing to MySql Database