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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:07:24+00:00 2026-05-27T14:07:24+00:00

I wrote a java code for inserting the current date but when I try

  • 0

I wrote a java code for inserting the current date but when I try to run it exception occurs:

public void Session_Table_Update (String Update_User) throws SQLException{
           String  SQL_Statement = null;
           error_Message = null;
            if (ds == null) throw new SQLException( error_Database = "No data source");      
       Connection conn = ds.getConnection();
            if (conn == null) throw new SQLException( error_Database = "No connection");      

       try {
            conn.setAutoCommit(false);
            boolean committed = false;
                try {
                    SQL_Statement = "INSERT INTO USERS (LAST_LOGIN) VALUES (?,?,?) WHERE USERZ ="+ Update_User;

                       PreparedStatement insertQuery = conn.prepareStatement(SQL_Statement);
                       insertQuery.setString(3, "2.2.2011");

                       insertQuery.executeUpdate();                  


                       conn.commit();
                       committed = true;
                 } finally {
                       if (!committed) conn.rollback();
                       }
            }
                finally {               
                conn.close();

                }  

           return;
       }

Can you help me to fix the problem?

  • 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-05-27T14:07:25+00:00Added an answer on May 27, 2026 at 2:07 pm

    You have three parameters (? characters) in your query, so you need to set that many parameters. You’re only setting one of these (the third one), so you need to have

    insertQuery.setString(1, "something");
    insertQuery.setString(2, "something else");
    insertQuery.setString(3, "2.2.2011");
    

    Or another set* method depending on your data type. See http://docs.oracle.com/javase/6/docs/api/java/sql/PreparedStatement.html

    As BalusC says, to set a date it would be better to use the setDate() method on your PreparedStatement. However, as you’re using Oracle, you may also consider using the TO_DATE Oracle function (see http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions183.htm), which converts a string to an Oracle date. e.g.

    "INSERT INTO USERS (LAST_LOGIN) VALUES (?,?,TO_DATE(?, 'D.M.YYYY')) WHERE USERZ ="+ Update_User;
    

    The format string can be changed to suit your needs

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

Sidebar

Related Questions

I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I wrote some Java code to generate pseudo-random numbers but I'm running into what
i wrote java code in beanshell but it throws java.lang.NoClassDefFoundError by defining DefaultHandler. I
I wrote this following java code to format the date and time in specific
Is there any maximum size for code in Java? I wrote a function with
I wrote some code to read a file in my Java Servlet class. (I'm
I've wrote a java code and compiled it. (foo1.6.class) According to my search, my
I wrote a piece of java code using threads, JDBC, Java Mail API etc.
I wrote this java J2SE code : import gnu.io.CommPort; import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; import
can someone please tell me the elegant way of inserting a java date instance

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.