Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connecting web application form with simple mysql command

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys,

Anyone here know how to insert and update record using simple prepared statement command (i'm using mysql). To insert record in jsp webform. I know there's other way, but it looks bit complicated to me (servlet,javabean,etc). The example code something similar down here :

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

Connection Conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/test","root","bbb213");
Statement Stmt = Conn.createStatement();

ResultSet resultset= Stmt.executeQuery
("SELECT * FROM student" WHERE StudID="?);

%>

<BR><table width="500" border="1" align="center" bgcolor="#99CCCC">
<tr bgcolor="#FFFFCC">
<td width="165"><strong>Student Info</strong></td>
<td width="8"> </td>
<td width="310"> </td>
</tr>
<tr>
<td>Student Name:</td>
<td>:</td>
</tr>
<tr>
<td>Student ID:</td>
<td>:</td>
</tr>


Pls, i need a simple jsp that can insert and update record properly.Thanks in advance.
 
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP is a view technology - you should not put any database / servlet code in it. This is how I would do it.

1. Create a new Servlet.



2. In your web.xml map the above servlet to the url "/processStudent" or something like that.

3. This is how your jsp should look like
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Database access code should not be in your servlet either. Fabricate a seperate set of classes to handle db related stuff. you can google for DAO pattern.

For prototyping stuff JSTL SQL tags is your best bet.
 
Do not set lab on fire. Or this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic