File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes servlets using JDBC Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets using JDBC" Watch "servlets using JDBC" New topic

servlets using JDBC

anubha goel

Joined: Jul 06, 2007
Posts: 22
I am trying to make a servlet program using JDBC.I am not getting how to refer to a particular button.My source code is:

And the corresponding HTML file is:

<form action="sam" method="Post">
name    <input type=text name=name><BR><BR>
age      <input type=text name=age><BR><BR>
class    <input type=text name=clas><BR><BR>
id    <input type=text name=id><BR><BR>

<input type=submit value=insert>  
<input type=submit value=select>  
I am able to compile it but when i run the Html file n press enter it displays page cannot be displayed...
Please help me out...
Thanks in Advance.


[BPSouther: Added code tags]
[ August 07, 2007: Message edited by: Ben Souther ]
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
There might be missing link , but this is what I would have done.

1> Move the database code out of servlet and unit test that to ensure that fetching of records from database is working fine.

2> Call the above code from within the servlet.

3> Check for the mapping of the servlet in web.xml to ensure that click on button on HTML page is invoking the servlets doGet method.

Just for you information , keep the driver library in WEB-INF's lib folder.
Hope this helps,

Rahul Bhattacharjee
LinkedIn - Blog
Amol Nayak
Ranch Hand

Joined: Oct 26, 2006
Posts: 218
Is the url /sam mapped to the servlet in your web.xml.

Can post the web.xml as well?

when you press the submit you should be getting something like (assuming its
running locally and on tomcat)

anubha goel

Joined: Jul 06, 2007
Posts: 22
i have followed all the steps as mentioned by Rahul.everything is working fine tha web.xml file is:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

Thanks & Regards,
I agree. Here's the link:
subject: servlets using JDBC
It's not a secret anymore!