Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8296509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:02:26+00:00 2026-06-08T15:02:26+00:00

I want to insert some session data in a database. I have one table

  • 0

I want to insert some session data in a database. I have one table called SESSIONINFO which has three columns, namely SESSIONID (text), USERID(text), LASTACCESSTIME(smalldatetime). But when I am trying to insert values in the database, it returns Jasper exception.

JSP that I am using :

<html>
<head><title>Enter to database</title></head>
<body>
<table>
<%@ page import="java.util.*" %>
<%@ page import="javax.sql.*;" %>
<% 

java.sql.Connection con;
java.sql.Statement s;
java.sql.ResultSet rs;
java.sql.PreparedStatement pst;

con=null;
s=null;
pst=null;
rs=null;

Date lastAccessTime = new Date(session.getLastAccessedTime());
//lastAccessTime = String("lastAccessTime");
String sessionID = session.getId();
String userName ="anni";

// Remember to change the next line with your own environment
String url= 
"jdbc:jtds:sqlserver://localhost/someDB";
String id= "testuser";
String pass = "testpasswd";
try{

Class.forName("net.sourceforge.jtds.jdbc.Driver");
con = java.sql.DriverManager.getConnection(url, id, pass);

}catch(ClassNotFoundException cnfex){
cnfex.printStackTrace();
}

String sql = "insert into SESSIONINFO (SESSIONID, USERID, LASTACCESSTIME) values ('"+sessionID+"', '"+userName+"', '"+lastAccessTime"')";
try{
s = con.createStatement();
rs = s.executeQuery(sql);
}
catch(Exception e){e.printStackTrace();}
finally{
if(rs!=null) rs.close();
if(s!=null) s.close();
if(con!=null) con.close();
}

%>

</body>
</html> 

Error –

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

An error occurred at line: 38 in the jsp file: /pages/insertsql.jsp
Syntax error on token ""\')"", delete this token
35: cnfex.printStackTrace();
36: }
37: 
38: String sql = "insert into SESSIONINFO (SESSIONID, USERID, LASTACCESSTIME) values ('"+sessionID+"', '"+userName+"', '"+lastAccessTime"')";
39: try{
40: s = con.createStatement();
41: rs = s.executeQuery(sql);


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:328)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:307)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:565)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

My select query works fine this way but seems there is something wrong in INSERT query syntax.

Kindly suggest. Thanks for all the help !!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T15:02:32+00:00Added an answer on June 8, 2026 at 3:02 pm

    You must add + after lastAccessTime.

    String sql = "insert into SESSIONINFO (SESSIONID, USERID, LASTACCESSTIME) values ('"+sessionID+"', '"+userName+"', '"+lastAccessTime + "')";
    

    by the way, it will still not work because you cannot just concatenate the Date object to your query. use PreparedStatement instead. you may check using text input to search Access date column with between/and for sample usage of PreparedStatement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table called 'studentdetails'. i dont want to insert the record one
I have a strongly typed view from which I want to insert some data.
I have some data enclosed in HTML tags. I want to insert this data
I want to insert some data into a table associated with dates for the
I want to insert some data into a table and I want the multiple
I have a table containing some datetime columns, now I want to get the
After creating a table (by migration), I want to insert some entries directly. How
Because of legacy data which is not available in the database but some external
I have a PHP script that inserts data into a mysql database. The table
I have a list of 10 data objects that I want to insert/update to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.