Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in inserting data into access database through jsp file

 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am a second year student and this is my semester project worth 55% and i dont have much knowledge about making connection b/w html form and access database so i tried it doing with the help of jsp but it is not working this is my html code:

<html>
<head>
<title>Student Co-op Willingness Form</title>
</head>
<body>
<form name="myform" action="example5.jsp" method=post>
<table border=0>
<tr>
<td>TRU-ID/G.C.No:</td>
<td><input type="text" name="tid" size=15 /></td>
</tr>

<tr>
<td>Enrollment No.:</td>
<td><input type="text" name="enroll" size=15 /></td>
</tr>

<tr>
<td>Name:</td>
<td><input type="text" name="name" size=15/></td>
</tr>

<tr>
<td>Course:</td>
<td><input type="text" name="course" size=15/></td>
</tr>

<tr>
<td>Semester:</td>
<td><input type="text" name="semester" size=15/></td>
</tr>

<tr>
<td>Company:</td>
<td><input type="text" name="company" size=15/></td>
</tr>

<tr>
<td>Skills:</td>
<td><input type="text" name="skills" size=20/></td>
</tr>

<tr>
<td>Email:</td>
<td><input type="text" name="email" size=20/></td>
</tr>

<tr>
<td>Contact No.:</td>
<td><input type="text" name="contact" size=20/></td>
</tr>

<tr>
<td>Work-Term:</td>
<td><input type="radio" name="radwt" value="1" size="5" >1 </td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="radwt" value="2" size="5">2</td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="radwt" value="3" size="5">3</td>
</tr>

<tr>
<td>Willing to opt for co-op:</td>
<td><input type="radio" name="radwc" value="yes"size="5" >Yes </td>
</tr>
<tr>
<td></td>
<td><input type="radio" name="radwc" value="no" size="5">No </td>
</tr>


<tr>
<td style="text-align:left">Co-op Arrangement:</td>
<td style="text-align:left">
<select name="arrange">
<option value="On Your Own">On Your Own</option>
<option value="By Institute">By Institute</option>
</select>
</td>
</tr>

<tr>
<td></td>
</tr>

<tr>
<td></td>
</tr>

<tr>
<td></td>
</tr>

<tr>
<td><input type="submit" value="Submit"/></td>
<td><input type="reset" /></td>
</tr>
</table>
</form>
</body>
</html>



this is my jsp file:
<%@ page import="java.sql.*" %>
<%
String url = "jdbcdbc:final";
String username="";
String password="";
Connection conn=null;
String classPath = "sun.jdbc.odbc.JdbcOdbcDriver";
try{
Class.forName(classPath);
conn = DriverManager.getConnection(url);
}catch(Exception exc){
out.println(exc.toString());
}
Statement stm=null;
String id;
String enroll;
String name;
String course;
String semester;
String company;
String skills;
String email;
String contact;
String workterm;
String willing;
String arrange;

id = request.getParameter("tid");
enroll = request.getParameter("enroll");
name = request.getParameter("name");
course = request.getParameter("course");
semester = request.getParameter("semester");
company = request.getParameter("company");
skills = request.getParameter("skills");
email = request.getParameter("email");
contact = request.getParameter("contact");
workterm = request.getParameter("radwt");
willing = request.getParameter("radwc");
arrange = request.getParameter("arrange");
<%= id%>
stm= conn.createStatement();
String query = "INSERT INTO Student VALUES("+ id +", " + enroll +", "+
name + "," + course +", "+ semester + ", "+ company +", " + skills +", "+
email + "," + contact +", "+ workterm + "," + willing +", "+
arrange + ")";
try{
stm.executeUpdate(query);
out.println("The data was added to the table successfully!");
}catch(Exception exc){
out.println("Inserting data failed!");
}
stm.close();
conn.close();
%>
<br><br><a href="coop.html">Add more record</a>



Please help me out. I am getting an error inserting data failed..... please please i have submit it within two days

thanks,
kanwal
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
exactly what error you are getting?
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

}catch(Exception exc){
out.println("Inserting data failed!");//Line 1
}


Replace Line 1 with exec.printStackTrace(); and analyze what exactly happening
wrong with your code.

Paste stack trace here so that we could help you also.
 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
thanks alot for your replies actually when i enter data into the html form the jsp file executes and it runs the exception "inserting data failed". So i am not getting what to do?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kanwal please try As Chandra Bhatt mentioned above and post your error message
 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there were some errors in my jsp file the jsp file without errors is:

<%@ page import="java.sql.*" %>
<%
String url = "jdbcdbc:final";
Connection conn = null;
String classPath = "sun.jdbc.odbc.JdbcOdbcDriver";
try{
Class.forName(classPath);
conn = DriverManager.getConnection(url);
}catch(Exception exc){
out.println(exc.toString());
}
Statement stm=null;
String id;
String enroll;
String name;
String course;
String semester;
String company;
String skills;
String email;
String contact;
String workterm;
String willing;
String arrange;

id = request.getParameter("tid");
enroll = request.getParameter("enroll");
name = request.getParameter("name");
course = request.getParameter("course");
semester = request.getParameter("semester");
company = request.getParameter("company");
skills = request.getParameter("skills");
email = request.getParameter("email");
contact = request.getParameter("contact");
workterm = request.getParameter("radwt");
willing = request.getParameter("radwc");
arrange = request.getParameter("arrange");
stm= conn.createStatement();
String query = "INSERT INTO Student VALUES ("+ id +", " + enroll +", "+
name + "," + course +", "+ semester + ", "+ company +", " + skills +", "+
email + "," + contact +", "+ workterm + "," + willing +", "+
arrange + ")";
try{
stm.executeUpdate(query);
out.println("The data was added to the table successfully!");
}catch(Exception exc){
out.println("Inserting data failed!");
}
stm.close();
conn.close();
%>
<br><br><a href="coop.html">Add more record</a>


and when i replaced:
out.println(exc.toString());
with
exec.printStackTrace();

it is giving this error:

type Exception report

message Internal Server Error

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

exception

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.


An error occured between lines: 2 and 51 in the jsp file: /jsp/final/example5.jsp

Generated servlet error:
C:\Program Files\Apache Tomcat 4.0\work\localhost\examples\jsp\final\example5$jsp.java:67: Undefined variable or class name: exec
exec.printStackTrace();
^
1 error, 1 warning

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:284)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:546)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:177)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:189)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:201)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2344)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:462)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1011)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1106)
at java.lang.Thread.run(Thread.java:536)
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

...


and when i replaced:
out.println(exc.toString());
with
exec.printStackTrace();

it is giving this error:

type Exception report
...




It was my typo,
you needed to make it exc.printStackTrace();

Weren't you able to recognize what caused this problem?
 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i made it exc but still it didn't work. i am so worried about this i am not getting what is wrong with it and if it didn't work i ll be failing this semester please help.....
 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and sir we both are getting the same error
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34195
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kanwal mandair:
Yes i made it exc but still it didn't work.

What do you mean my "didn't work" ? Did it give you a compiler error on the stack trace or did it display the stack trace? Without the stack trace, people aren't going to be able to give you advice.
 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this was the error:

type Exception report
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by kanwal mandair:
this was the error:

type Exception report



Please paste complete stack trace of the error you got after making the
relevant changes you did.
 
Srikanth Nutigattu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
willing = request.getParameter("radwc");
arrange = request.getParameter("arrange");
<%= id%>
stm= conn.createStatement();
String query = "INSERT INTO Student VALUES("+ id +", " + enroll +", "+


In the JSP code you have posted, you messed up with the scripting elements <%...%>. You remove the line which I have highlighted in bold.

After removing the line, I have compiled your file and it compiled successfully.
 
kanwal mandair
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all i have completed my task....thanks a lot for your help now please can anyone tell that how can i show multiple records in access forms...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic