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 9252365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:55:36+00:00 2026-06-18T10:55:36+00:00

In my application I passed date value (as string) as parameter to Servlet. In

  • 0

In my application I passed date value (as string) as parameter to Servlet. In Servlet code, I converted the string to sql date as “2013-02-05” (yyyy-MM-dd).

Example: dat=”05/02/2013″ converted to sqlDate=”2013-02-05″.
My servlet code is

 dat= request.getParameter("dat");
 //dat="05/02/2013";
     try
     {
         java.util.Date date=new SimpleDateFormat("dd/MM/yy").parse(dat);
         //out.println(date);
         sqlDate = new java.sql.Date(date.getTime());
         //out.println(sqlDate);
     }
     catch(Exception e)
     {

     }

if(div_code!=null)
{
try
{

 Class.forName("oracle.jdbc.driver.OracleDriver");
 java.sql.Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@xxx.xxx.x.xxx:xxx:pdsm", "test", "test");
 Statement stmt=conn.createStatement();
     ResultSet rs=stmt.executeQuery("insert into offer1 values('"+r_code+"','"+v_name+"','"+vcode+"','"+div_code+"','"+sec_code+"','"+extent+"','"+phone+"','"+sqlDate+"','"+loan+"','"+seeds+"','"+offerno+"','"+loc+"')");
      conn.setAutoCommit(true);
      out.println("data inserted");

   }catch(Exception e)
    {
       out.println(e);
    }
 }

When I’m calling this from android application, it shows error as “ORA-01861: literal doesn’t match format string“. The format I’ve used is shown correct result when I tested with sample input. But data didn’t get inserted.

What is the problem in my code? Why am I receiving this error? Do I need to convert further? If yes, then how?

Also, someone explain can I use pl/sql function (to_date()) in servlet? Because it is easy to convert date

Edit: Modified Code:

String query="insert into offer1('RCODE','OFFERNO','DAT') values(?,?,?)"; 
PreparedStatement ps=conn.prepareStatement(query);
ps.setString(1,r_code);
ps.setString(2,offerno);
ps.setDate(3,sqlDate);
ResultSet rs=ps.executeQuery();
out.println("data inserted");
  • 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-18T10:55:37+00:00Added an answer on June 18, 2026 at 10:55 am

    First of all don’t frame your query like this (appending everything into a single string).

    It is vulnerable to SQL injection See SQL injection

    So better use PreparedStatement as it will protect you from SQL injection and your conversion tasks for various values will be automatically taken care of.

    So if you have a java.sql.Date variable sqlDate and now you want to insert it in the database: then you need these simple steps:

    String query = "insert into your_table_name(`name`,`myDate`) values(?,?)";
    PreparedStatement ps = conn.prepareStatement(query);
    //now just set the values like this
    ps.setString(1,"ABC");
    //note index starts at 1
    ps.setDate(2,sqlDate);
    ResultSet rs = ps.executeQuery();
    

    Now hope you can figure out how to do it for yourself.

    For more information see this and this

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

Sidebar

Related Questions

I have a web application which uses the globalization values being passed from sql
I'm working on an application where dates are passed as yyyy-mm-dd but displayed to
I have a procedure that defaults todays date if no parameter is passed into
I have an application that passes in java.util.Date. I want to check whether this
Since Compact Framework calls Show() on the form passed to Application.Run() , I decided
The application I have inherited is configured by a properties file passed in with
I am writing an application (a multiplayer game) where objects need to be passed
My application (obviously) uses a unique ID to distinguish records. This UID is passed
Server Error in '/' Application. The model item passed into the dictionary is of
I'm creating a console application in C# to which, at execution, it is passed

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.