This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Cloud Application Architecture Patterns: Designing, Building, and Modernizing for the Cloud and have Kyle Brown, Bobby Woolf and Joseph Yodor on-line!
See this thread for details.
  • 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic