![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Posts: 1
Rep Power: 0
![]() |
Trying to write jsp files to MySql Database
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? |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
yeah you need to have a action, otherwise when you click the submit button nothing will happen. you really just need to put the page name in and then have a switch (if statment, switch what ever you feel like) that uses a GET varible in the address bar.
so something like this: <form method="post" action="mypage.jsp?action=db" name="form1"> then have something like this: if (action == "db")
{
do something with the db.
}i am not a java developer, so i am not sure how to get the varible from teh address bar with it. in php, it would be: [PHP] $_GET['action'] [/PHP] anyways, hopes this gives you some ideas on how to do it.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|