i want to create a simple form which stores date in to a ms access db

so i created a form register.html and action user_register.jsp

i also created a ms aceess db

when i fill the form the data is passed to the Auction.mdb but the server shows error


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /user_register.jsp:11

8: <% Statement myStatement = myConn.createStatement (); %>
9: <% String StrUser = request.getParameter("username"); %>
10: <% String StrPass = request.getParameter("password"); %>
11: <% ResultSet myResult = myStatement.executeQuery("INSERT INTO Auction([UserName], [Password]) VALUES ('"+StrUser+"', '"+StrPass+"')"); %>
12: <% myConn.close(); %>
13: </BODY>
14: </HTML>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

javax.servlet.ServletException: No ResultSet was produced
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.user_005fregister_jsp._jspService(user_005fregister_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.sql.SQLException: No ResultSet was produced
sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:259)
org.apache.jsp.user_005fregister_jsp._jspService(user_005fregister_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.

the regiser.html is

<html>
<head>
<title>Welcome to the Action...</title></head>
<body>
<form action="user_register.jsp" method="post">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="submit" name="okfunc" value="OK">
</form></body></html>

user_register.jsp is

<HTML>
<BODY>
<%@ page language="java" import="java.sql.*" %>
<%  String url = "jdbc:odbc:Auction", user="", passwd=""; %>
<%   Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<%--<%   Connection myConn = DriverManager.getConnection (url, user, passwd); %> --%>
<% Connection myConn = DriverManager.getConnection("jdbc:odbc:Driver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb"); %>
<%   Statement myStatement = myConn.createStatement (); %>
<% String StrUser = request.getParameter("username"); %>
<% String StrPass = request.getParameter("password"); %>
<%   ResultSet myResult = myStatement.executeQuery("INSERT INTO Auction([UserName], [Password]) VALUES ('"+StrUser+"', '"+StrPass+"')"); %>  
<% myConn.close(); %>   
</BODY>
</HTML>

i m very new to jsp so any help wud be gr8
thanx in advance

Welcome ankurmawanda,

Its difficult to read your source code. Use bb code tags to post source code. See # icon at toolbar and also read How to use bb code tags?.

[code=Jsp] ... ... your source code..

[/code]

this is the server error log


HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /user_register.jsp:11

8: <% Statement myStatement = myConn.createStatement (); %>
9: <% String StrUser = request.getParameter("username"); %>
10: <% String StrPass = request.getParameter("password"); %>
11: <% ResultSet myResult = myStatement.executeQuery("INSERT INTO Auction([UserName], [Password]) VALUES ('"+StrUser+"', '"+StrPass+"')"); %>
12: <% myConn.close(); %>
13: </BODY>
14: </HTML>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:355)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

javax.servlet.ServletException: No ResultSet was produced
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:841)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:774)
org.apache.jsp.user_005fregister_jsp._jspService(user_005fregister_jsp.java:77)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.sql.SQLException: No ResultSet was produced
sun.jdbc.odbc.JdbcOdbcStatement.executeQuery(JdbcOdbcStatement.java:259)
org.apache.jsp.user_005fregister_jsp._jspService(user_005fregister_jsp.java:66)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.


the register.html file

<html>
<head>
<title>Welcome to the Action...</title></head>
<body>
<form action="user_register.jsp" method="post">
Username:<input type="text" name="username">
Password:<input type="password" name="password">
<input type="submit" name="okfunc" value="OK">
</form></body></html>

the user_register.jsp

<HTML>
<BODY>
<%@ page language="java" import="java.sql.*" %>
<% String url = "jdbc:odbc:Auction", user="", passwd=""; %>
<% Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver"); %>
<%--<% Connection myConn = DriverManager.getConnection (url, user, passwd); %> --%>
<% Connection myConn = DriverManager.getConnection("jdbc:odbcriver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb"); %>
<% Statement myStatement = myConn.createStatement (); %>
<% String StrUser = request.getParameter("username"); %>
<% String StrPass = request.getParameter("password"); %>
<% ResultSet myResult = myStatement.executeQuery("INSERT INTO Auction([UserName], [Password]) VALUES ('"+StrUser+"', '"+StrPass+"')"); %>
<% myConn.close(); %>
</BODY>
</HTML>

Use single scriptlet if possible. To execute Non-query(Insert/delete/update/create/alter) use executeUpdate() method.

If the given connection url fails then use System DSN.

<HTML>
<BODY>
  <%@ page language="java" import="java.sql.*" %>
 <% 
    String url = "jdbc:odbc:Auction", user="", passwd=""; 
   Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection myConn = DriverManager.getConnection("jdbc:odbcriver={MicroSoft Access Driver (*.mdb)};DBQ=C:/Auction/Auction.mdb");
  Statement myStatement = myConn.createStatement ();
  String StrUser = request.getParameter("username");
  String StrPass = request.getParameter("password");

  myStatement.executeUpdate("INSERT INTO Auction([UserName], [Password]) VALUES ('"+StrUser+"', '"+StrPass+"')");
  myStatement.close();
  myConn.close(); 

%>
</BODY>
</HTML>

the value filled in the form are getting stored in the auction .mdb database but i still get a server error 500....

thanx in advance

thanku adatapost for ur reply

Error 500 shows that your page script has some problems. Let us know - How did you create your web application? - manually or netbean.

Error 500 shows that your page script has some problems. Let us know - How did you create your web application? - manually or netbean.

i did it manually...............i am using tomcat apache 5.5.27

actually i googled the code

Do you know how to create a web context? Actually, first you have to create web-context. Do you know the structure of Web application?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.