File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Writing to MySql Database" Watch "Writing to MySql Database" New topic
Author

Writing to MySql Database

Reuben Fields
Greenhorn

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:

<%
Class.forName("com.mysql.jdbc.Driver");
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 + "')";

stmt.executeUpdate(sqlstr);


stmt.close();
conn.close();

%>

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

<form name="form1" action="" method=post>
<p>Name:
<input type="text" name="name" size="10" maxlength="25">
</p>
<p>Password:
<input type="text" name="password" size="10" maxlength="25">
</p>
</form>

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
Greenhorn

Joined: Apr 05, 2005
Posts: 15
Class.forName("com.mysql.jdbc.Driver");

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?

Class.forName("org.git.mm.mysql.Driver");

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

Joined: Feb 08, 2004
Posts: 1281
this?


java amateur
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61187
    
  66

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
Greenhorn

Joined: Apr 05, 2005
Posts: 15
Would both

Class.forName("com.mysql.jdbc.Driver");

Class.forName("org.git.mm.mysql.Driver");

work with this driver?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing to MySql Database