garimat
08-20-2008, 02:41 PM
hi..
im trying to use JDBC...i am using JSP where i have made a form for entering data for books details and enter it in database table thru JDBC. then retrieve the same data and display on a html form...on running this jsp on tomcat server there is an error...plz tell me wt shoul i do or wt is wrong...its urgent plz...the code coloured in red was the problem area i think...problem might be somewhere else also...
<%@ page language="java"%>
<%@ page contentType="text/html"%>
<%@ page import="java.sql.*" %>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:80/myusers","admin","");
stmt = con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
if(request.getParameter("action")!=null)
{
String bookname=request.getParameter("bookname");
String author=request.getParameter("author");
stmt.executeUpdate("insert into books_details(book_name,author) values(+bookname+,+author+);");
rs=stmt.executeQuery("select * from books_details;");
%><html>
<body>
<center>
<h2>Books List</h2>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>S.No</b></td>
<td><b>Book Name</b></td>
<td><b>Author</.b></td>
</tr>
<%
int no=1;
while(rs.next()){
%>
<tr>
<td><%=no%></td>
<td><%=rs.getString("book_name")%></td>
<td><%=rs.getString("author")%></td>
</tr>
<%
no++;
}
rs.close();
stmt.close();
con.close();
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
<head>
<title>Book Entry FormDocument</title>
<script language="javascript">
function validate(objForm){
if(objForm.bookname.value.length==0){
alert("Please enter Book Name!");
objForm.bookname.focus();
return false;
}
if(objForm.author.value.length==0){
alert("Please enter Author name!");
objForm.author.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<form action="connection.jsp" method="post" name="entry" onSubmit="return validate(this)">
<input type="hidden" value="list" name="action">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Book Entry Form</h2></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>Book Name:</td>
<td><input name="bookname" type=
"text" size="50"></td>
</tr>
<tr>
<td>Author:</td><td><input name=
"author" type="text" size="50"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%}%>
these exceptions are encountered:
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException
im trying to use JDBC...i am using JSP where i have made a form for entering data for books details and enter it in database table thru JDBC. then retrieve the same data and display on a html form...on running this jsp on tomcat server there is an error...plz tell me wt shoul i do or wt is wrong...its urgent plz...the code coloured in red was the problem area i think...problem might be somewhere else also...
<%@ page language="java"%>
<%@ page contentType="text/html"%>
<%@ page import="java.sql.*" %>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection con=null;
ResultSet rs=null;
Statement stmt=null;
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:80/myusers","admin","");
stmt = con.createStatement();
}
catch(Exception e){
System.out.println(e.getMessage());
}
if(request.getParameter("action")!=null)
{
String bookname=request.getParameter("bookname");
String author=request.getParameter("author");
stmt.executeUpdate("insert into books_details(book_name,author) values(+bookname+,+author+);");
rs=stmt.executeQuery("select * from books_details;");
%><html>
<body>
<center>
<h2>Books List</h2>
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td><b>S.No</b></td>
<td><b>Book Name</b></td>
<td><b>Author</.b></td>
</tr>
<%
int no=1;
while(rs.next()){
%>
<tr>
<td><%=no%></td>
<td><%=rs.getString("book_name")%></td>
<td><%=rs.getString("author")%></td>
</tr>
<%
no++;
}
rs.close();
stmt.close();
con.close();
%>
</table>
</center>
</body>
</html>
<%}else{%>
<html>
<head>
<title>Book Entry FormDocument</title>
<script language="javascript">
function validate(objForm){
if(objForm.bookname.value.length==0){
alert("Please enter Book Name!");
objForm.bookname.focus();
return false;
}
if(objForm.author.value.length==0){
alert("Please enter Author name!");
objForm.author.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<center>
<form action="connection.jsp" method="post" name="entry" onSubmit="return validate(this)">
<input type="hidden" value="list" name="action">
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td>
<table>
<tr>
<td colspan="2" align="center">
<h2>Book Entry Form</h2></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td>Book Name:</td>
<td><input name="bookname" type=
"text" size="50"></td>
</tr>
<tr>
<td>Author:</td><td><input name=
"author" type="text" size="50"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Submit"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
<%}%>
these exceptions are encountered:
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.ClassNotFoundException