• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is this problem of sql query or JSP

 
suraj savaratkar
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi;

I'm going to insert to sql query in ms access database. But when i submit the details tomcat shows an following error message :

type Exception report

message

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

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 22 in the jsp file: /jsp/fare.jsp
String literal is not properly closed by a double-quote
19:
20: try
21: {
22: String qry = "insert into fare(trainno,tdate,sourcestation,destinationstation,classcat,agecat,concission)
23: values(11,'acd','acac','acas','acc','acac','cacsc');";
24: Class.forName("sun.jdbc.JdbcOdbcDriver");
25: Connection con = DriverManager.getConnection("jdbc:odbc:Database1");


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:319)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
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)

fare.jsp



<%@page import="java.sql.*"%>

<%
String tno = request.getParameter("tno");
Integer trno = Integer.parseInt(tno);
String dat = request.getParameter("dt");
String src = request.getParameter("src");
String dst = request.getParameter("dst");
String cls = request.getParameter("class");
String ag = request.getParameter("age");
String consc = request.getParameter("concsn");
int up = 100;




// values('" + trno + "','" + dat + "','" + src + "','" + dst + "','" + cls + "','" + ag + "','" + consc + "')";


try
{
String qry = "insert into fare(trainno,tdate,sourcestation,destinationstation,classcat,agecat,concission)
values(11,'acd','acac','acas','acc','acac','cacsc');";
Class.forName("sun.jdbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:Database1");
Statement st = con.createStatement();
up = st.executeUpdate(qry);
con.close();
out.println("Data is successfully inserted into database.");
}
catch(ClassNotFoundException e)
{
System.out.println(e);
e.getCause();
e.getException();
}



if(up==0) //count the row
response.sendRedirect("../homeimages/fare.html");
if(up==1) //no rows exists
response.sendRedirect("../homeimages/error.html");




%>



is thier wrong sql query or something else.
Please help me.

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34205
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a JSP error. YOu are missing a close quote somewhere. THis highlights why it is better to not have Java code in a JSP. It is hard to troubleshoot.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34205
341
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Is this really two lines in your JSP? If so, this is the error. It should be
 
suraj savaratkar
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



Thanks for suggestion;

But still no error has shown also no data has been stored into the database.
What could be the problem with ?
 
K. Tsang
Bartender
Posts: 3403
13
Android Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For that query line, I don't think you need the semi-colon inside the double quotes. But this may not solve your not storing data.
 
suraj savaratkar
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping;
Problem has solved...


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic