aspose file tools*
The moose likes JSP and the fly likes is this problem of sql query or JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "is this problem of sql query or JSP" Watch "is this problem of sql query or JSP" New topic
Author

is this problem of sql query or JSP

suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
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

Joined: May 26, 2003
Posts: 30764
    
156

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30764
    
156



Is this really two lines in your JSP? If so, this is the error. It should be
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67



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

Joined: Sep 13, 2007
Posts: 2524
    
    8

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.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
suraj savaratkar
Ranch Hand

Joined: May 17, 2010
Posts: 67
Thanks for helping;
Problem has solved...


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: is this problem of sql query or JSP