Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 14th, 2005, 9:45 AM   #1
reubenfields
Newbie
 
Join Date: Apr 2005
Posts: 1
Rep Power: 0 reubenfields is on a distinguished road
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?
reubenfields is offline   Reply With Quote
Old Apr 14th, 2005, 9:51 AM   #2
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
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!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:03 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC