• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing to MySql Database

 
Reuben Fields
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Reuben Fields
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This would be more appropriate in the JDBC forum.

Also changed the topic title to better suit subject matter.
 
Reuben Fields
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would both

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

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

work with this driver?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic