Date in PreparedStatements

Since the search is broken I apologize if this is a repeat.
I am not using OraclePreparedStatement.
I am using the thin client for Oracle 8i and all associated software (Driver, database, etc).
I am using format {d '2002-04-04'} for date in parameter and am getting error ORA-01858 - non-numeric character found when one expected.
Why?
I am using the described date format in the JDBC programming guide. What am I missing?
The statement looks fine. I have displayed the SQL and the values. What is next?
Please help

I've run into this error before and what it usually indicates is that the value supplied for date conversion is either of the wrong format, or contains a character not specified in the date format.
If you're using this format '2002-04-04' then the SQL statement should read
to_date(?, 'YYYY-MM-DD')
I was sure which was the month, or which was the day, but you get the point. Not sure if that answers your question, but if it doesn't provide more info and I'll do a better job at addressing the question more specifically.

Similar Messages

  • Error IllegalArgumentException in java.sql.Date used PreparedStatement

    I'm found bug (probably). I have a table with column DATA type. Now I connect do database use JDBC in Java, and create PreparedStatement:
    PreparedStatement stmt = conn.prepareStatement("insert into \"Appuser\" (\"IDUser\", \"createAccountDate\") values (?,?)");
    Column createAccountDate is a DATA type. And now I invoke:
    stmt.setInt(1, 1);
    stmt.setInt(2, new java.sql.Date(-2508265596206959779));
    stmt.execute();
    and last line return exception:
    java.lang.IllegalArgumentException
    at sun.util.calendar.ZoneInfo.getOffset(ZoneInfo.java:368)
    at oracle.jdbc.driver.DateCommonBinder.zoneOffset(OraclePreparedStatement.java:15423)
    at oracle.jdbc.driver.DateCommonBinder.setOracleCYMD(OraclePreparedStatement.java:15561)
    at oracle.jdbc.driver.DateBinder.bind(OraclePreparedStatement.java:15641)
    at oracle.jdbc.driver.OraclePreparedStatement.setupBindBuffers(OraclePreparedStatement.java:2866)
    at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2151)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3280)
    at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3390)
    at // line stmt.execute();
    Another values of Data are OK. Probably value -2508265596206959779 cause that error.
    It's a bug? Better will be SQLException if it is a bug.
    My configuration:
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
    PL/SQL Release 10.2.0.1.0 - Production
    CORE     10.2.0.1.0     Production
    TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Windows XP SP3, Java 1.6.0_20,
    ojdbc14.jar, Oracle JDBC Driver version - "10.2.0.1.0XE

    Probably value -2508265596206959779 cause that errorMaybe, whatever that .date( -ReallyLotsOfmSec ) date values is, pretty sure its outside the valid values for a date column, 4712BC to 9999AD is the min/max.
    Perhaps the java code can handle it, an oracle date type can not.

  • DATE and PreparedStatement

    I'm trying to update a table using a PreparedStatement. Always receive the following SQL exception : ORA-01858: a non-numeric character was found where a numeric was expected. I send my date parameter has a string and try to convert them using the TO_CHAR/TO_DATE function.
    String psQuery = "update requ_ord set adj_horizon_date=? where ...";
    PreparedStatement pSt = conn.prepareStatement(psQuery);
    pSt.setString(1, "TO_DATE('2000-03-10', 'YYYY-MM-DD')");
    pSt.execute();
    null

    Hi,
    Your SQL statement is equivalent to
    update xxx set sdate='TO_date('2000-01-01','yyyy-mm-dd')'
    Above statement will give same error which you were getting..
    what you can do is change your sql statement to
    String psQuery = "update requ_ord set adj_horizon_date=to_date(?,'yyyy-mm-dd') where ...";
    Suresh
    null

  • Adding date to PreparedStatement?

    Hello,
    I created a table in mysql to store some information about the users, and wish to add the current date to the preparedstatement.
    I am using the DATE type field in the table, the date being added is always 01.01.2006
    Could anyone advise how to change this to the current date.
    Calendar calendar = new GregorianCalendar(2006,0,1);
    Date date = new Date(calendar.getTime().getTime());
    statement = conn.prepareStatement(sql);
    statement.setString(1,userfolder);
    statement.setDate(2,date);
    statement.executeUpdate();  Thanks

    What's wrong with the zero-argument constructor of GregorianCalendar? Its documentation says
    "Constructs a default GregorianCalendar using the current time in the default time zone with the default locale."
    That's if you just have the code posted and want to make the smallest possible change. If you want something less blatantly obvious, then drop the calendar bit and do this:Date date = new Date(System.currentTimeMillis());

  • How to insert the system date  using PreparedStatement

    How do I insert system date(from Orcale database) using
    PreparedStatement. I am aware that that oracle has date
    function 'sysdate' to retrieve the database current date.
    How Do i use that in the following syntax?
    Alertnative 1:
    String inssql =
    "insert into emp (empid, name, dept, updateDate) "+
    " values (?, ?, ?, ?)";
    PreparedStatement pstmt = conn.prepareStatement(inssql);
    pstmt.setInt(1, 123456);
    pstmt.setString(2, "Bougnon Kipre");
    pstmt.setString(3, "Rare Species Depatement" );
    pstmt.setDate(4, sysdate) // if this okay
    pstmt.executeUpdate();
    Alternative 2:
    String inssql =
    "insert into emp (empid, name, dept, updateDate) "+
    " values (?, ?, ?, sysdate)";
    PreparedStatement pstmt = conn.prepareStatement(inssql);
    pstmt.setInt(1, 123456);
    pstmt.setString(2, "Bougnon Kipre");
    pstmt.setString(3, "Rare Species Depatement" );
    pstmt.executeUpdate();

    Hi,
    The second alternative will be the best way.
    Since the alternative 1 won't work. sysdate cannot be accessed
    from java as a variable. Either use alternative two or create a
    java.sql.Date and insert it.
    Regards
    Elango

  • How to insert date from preparedstatement

    hi,
    I have a problem here trying to insert date into my table. but the problem is the date is supposed to be grabbed from the user input which is in textfield. However, I did a short cut and made the list of data into and array of String. so when i tried to insert the data into the table it gives me this error:
    ORA-01861: literal does not match format string
    so, I would like to ask if there is a solution to insert date into the table with the use of prepared statement..
    for (int i=0; i<str_val.length; i++){
                    ps.setString(i+1, str_val);
    ps.executeUpdate();
    con.commit();
    this is how i insert data using prepared statement. but the date is causing problem. Helps please....
    Thanks in advance

    I have a problem here trying to insert date into my
    table. but the problem is the date is supposed to be
    grabbed from the user input which is in textfield.So you have a string which is supposed to contain a date (or timestamp.)
    Presumably you verified it.
    You have two choices...
    1. Create your SQL for your prepared statement using the oracle function todate(). You will need to use the exact format string, as defined by the function, that corresponds to the text field you have.
    2. Use SimpleDateFormat to parse the string into a date. Use another SimpleDateFormat to parse the date into the format expected by oracle.

  • PreparedStatement.setDate(1,java.sql.Date x) problem

    I am using Sun JDBC-ODBC bridge to access MS SQL Server 2000. I have following statement:
    java.util.Date date = new java.util.Date();
    java.sql.Date expire_date = new java.sql.Date(date.getTime());
    PreparedStatement pstat = con.prepareStatement("update account set expire_date=? where userid=?");
    pstat.setDate(1,expire_date);
    pstat.setString(2,userid);
    When I ran the program, I got a SQLException error as
    java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]Optional features not implemented.
    I have traced the problem happened in the statement pstat.setDate(1,expire_date). I use jdbc-odbc bridge from j2se 1.3.1.
    I appreciate any help.
    Thanks, Brian

    May I refer to a recent topic where I explained a lot about date conversion between JDBC and SQLServer?
    http://forum.java.sun.com/thread.jsp?forum=48&thread=241049
    Try how far this helps you, then ask more.

  • Dynamic insertion of data in a Dynamic Column in a table

    Hi EveryBody ,
    I have a table where i am increasing the column dynamically . I need to insert data through PreparedStatement Like
    pst = con.prepareStatement(CBBsqlConstants.addOrderItem);
                   pst.setString(1,ein);
                   pst.setString(2,insert_date);
                   pst.setString(3,checkList);
                   pst.setString(4,Quantities);
                   pst.setDate(5,pick_date);
                   pst.setDate(6,completed_date);
                   pst.setString(7,comment);
                   pst.setInt(8,status);
                   pst.setString(9,agent_ein);
                   i = pst.executeUpdate();
    But here my column is increasing dynamically, so the above cant be constant as column is incresing . how do i handle the insertion part dynamically.
    Thanks So much . Please help with this .

    Server_java wrote:
    Ya you are right ,
    Take i am ordering some Items and quantity from checkbox and inserting that to the table , each item and quantity is going to consume a row , but when i am going have column for each item , all the items i am going to select is going to appear in a single row . so i am consuming .But only 256 column is allowed for a table ,but my item is not going to excced that . That maximum number of columns is the least of the problems here.
    The problem is that you are taking data that should be in another table and turning it into metadata instead. That's a mistake because it makes your entire application brittle and it doesn't need to be. It also will make querying your table a nightmare.
    Let's take a look at your solution and then the correct solution.
    Your solution (condensed)
    tblOrder
    id
    customername
    apples
    oranges
    bananas
    cherries
    Sample data (CSV format for the forum)
    1,"John Smith",0,0,0,1
    2,"Jane Smith",1,0,0,3
    3,"Kate Smith",0,2,1,0
    The correct solution
    tblOrder
    id
    customername
    Sample data
    1,"John Smith"
    2,"Jane Smith"
    3,"Kate Smith"
    tblProduct
    id
    name
    Sample data
    1, "Apples"
    2,"Oranges"
    3, "Bananas"
    4, "Cherries"
    tblOrderItem
    orderid
    productid
    quantity
    Sample data
    1,4,1
    2,1,1
    2,4,3
    3,2,2
    3,3,1
    So what's the difference?
    With your design what happens when you want to add a new fruit? Your schema changes and all your code breaks. With my design you simply insert one row and that's it.
    And what happens if you do happen to eventually need more than 250 odd fruits? With your design you are screwed. With my correct design it's never going to be a problem.
    And consider that with my design you can populate user inteface components using actual data and not table meta data.
    And the list goes on... the point is the only correct solution is to use a proper relational design.

  • How to involve time in a date column in JDBC OCI 8.0.5.2.

    Hi,
    I need to involve time in a date column in JDBC OCI 8.0.5.2.
    The default date format is like "09-Sep-1999". I could use it
    but just need time involved too, like "09-Sep-1999 10:11:12".
    I tried to use JDBC's Timestamp whose format is like
    1999-9-9 12:00:00.000, just same as the dates selected from my
    table,
    but got an error message "literal doesn't match format string".
    The JDBC document said Oracle's date could be JDBC date,
    timestamp and char.
    Thanks a lot!
    -Ninon
    null

    : The only oracle driver that vcan run with JDK 1.2.x is in the
    OTN
    : download area and is named "816SDK for JDK 1.2"
    : it will work with the JDK 1.2.X using the JDBC 1.22 spec from
    JDK
    : 1.1.X.
    : IT DOES NOT PROVIDE THE FULL JDBC 2.0 FEATURES/ FUNCTIONALITY
    : THAT ARE INCLUDED IN THE JDK 1.2.X CLASSES.
    Does anyone know which versions of Oracle this driver will work
    with? I'm trying to use JDK 1.2 and Oracle 8.04 with the above
    mentioned driver, but it's misbehaving on prepared statements:
    I'm getting a 'ORA-8001 not all variables bound' error even
    though I'm correctly specifying binary data (using
    PreparedStatement.setBytes(..)) for a LONG RAW column...
    Please don't tell me I have to upgrade my Oracle installation in
    order to use JDBC with JDK 1.2.x
    Feedback is greatly appreciated!
    thanks!
    // Tor Kleiberg
    null

  • Converting from milliseconds to a date format in java

    This so that, that date can be inserted into a date column in mysql
    What I have is something like 1119193190
    I do:
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm");
    Date resultdate = new Date(yourmilliseconds);
    System.out.println(sdf.format(resultdate));
    and Java gives me something like:
    Jul 04,2004 14:06
    But Java then when inserting into a mysql table is all like um....no:
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'Jul 04,2004 14:06' for column 'prodDate' at row 1
    proDate is of type date in mysql.
    Help?

    jverd wrote:
    "Jul 04,2004 14:06" is a String, not a Date.
    PreparedStatement ps = conn.prepareStatement("insert into T(name, birthdate) values(?, ?)");
    ps.setString(1, "Joe Smith");
    java.sql.Date date = new java.sql.Date(yourmillis);
    ps.setDate(2, date);
    ps.executeUpdate();
    I am a bit confused
    This i what I have
    for(int i = 0; i < productions.size(); i++)
                        //Create a new Production from the ArrayList
                        Production p = (Production) productions.get(i);
                        //Convert the date from milliseconds to YYYY-MM-DD format. for mysql?
                        SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd,yyyy HH:mm");
                        Date convertedDate = new Date(p.getDate());
                        //Build a query to insert the Production into the table
                        String insertQuery = "INSERT INTO WELL_PROD VALUES(" +
                                  "'" + p.getLocation() + "'," +
                                  "'" + dateFormatter.format(convertedDate) + "'," +
                                  "'" + p.getOilProd() + "'," +
                                  "'" + p.getWaterProd() + "'," +
                                  "'" + p.getGasProd() + "')";
                        //Print the query to the screen
                        System.out.println("-> INSERTING the following query into well_prod: ");
                        System.out.println("   " + insertQuery);
                        //Update the database using the constructed query
                        int result = statement.executeUpdate(insertQuery);
                        //Print out the result of the insertion
                        System.out.println("   INSERT RESULT: " + result);
                   }Are you saying something like
    java.sql.Date date = new java.sql.Date(Something , what I have no idea, Should go here);
    instead of
    SimpleDateFormat dateFormatter = new SimpleDateFormat("MMM dd,yyyy HH:mm");
    and then carry on as normal?
    If so, what should go in those brackets based on the code?
    java.sql.Date date = new java.sql.Date("MMM dd,yyyy HH:mm");
    This is all being read in from a text file and converted over before being spit out to the data base, it all works except for the date...

  • How does preparedstatement work?

    In jb9 online book, it said "An object that represents a precompiled SQL statement. A SQL statement is precompiled and stored in a PreparedStatement object. This object can then be used to efficiently execute this statement multiple times. ". But in practice, wo usually close it after wo excute it.
    How can it execute multiple times.

    hi,
    suppose u have a collection of data,
    U can insert that data using preparedstatement,
    in this instance u r using the same precompiled preparedstatemnt
    multiple times to insert the collection of data.
    thx,
    abdul.

  • Conversion of JDBC date to SQL date!!

    I've a date format of "Sun Dec 03 01:18:11 IST 2006" (JDBC format)
    and want to convert in into "2006/12/03 01:18:11:00" (SQL format).
    I've tried with SimpleDateFormat, but it didn't work. It is not accepting that value or format.
    Could anyone help me out!!!!

    JDBC format? SQL format? Huh?
    You need to be working with java.sql.Date and PreparedStatements to properly escape the Date in the database.
    As for the SimpleDateFormat, what does "not work" look like?
    package cruft;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;
    * DateFormatTest
    * @author md87020
    * @since Dec 20, 2006
    public class DateFormatTest
       public static void main(String[] args)
          DateFormat formatter = new SimpleDateFormat("E MMM dd hh:mm:ss z yyyy");
          for (int i = 0; i < args.length; ++i)
             try
                Date date = null;
                date = formatter.parse(args);
    System.out.println(date);
    catch (ParseException e)
    System.err.println("i: " + i + " value: " + args[i]);
    e.printStackTrace();
    This program appears to be doing some Locale conversions for me, and I don't have time to sort it out.
    But the idea is that you should be sending java.sql.Date to the database. Let the JDBC driver handle any SQL conversions for you with PreparedStatements.

  • Sql.Date problem

    Hi,
    I am using java.sql.Date and preparedStatement for SQL select query, something like
    : select app_id, entry_date, message from testTable where entryDate >= ? and entryDate <= ?
    for example i'am supplying date as yesturday's date and i want data where
    say: 24-Oct-2005 12:00:00AM to 24-Oct-2005 11:59:59PM, basically whole days data.
    <code>
    SimpleDateFormat formatter =
    new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
    SimpleDateFormat formatter1 =
    new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss aaa", Locale.US);
    String new1 = formatter1.format(formatter.parse(dateStr));
    System.out.println("new1 : "+ new1);
    Date date = new Date(formatter1.parse(new1).getTime());
    long nextDate = date.getTime()+(23*60*60*1000);
    System.out.println("d: " + date);
    System.out.println("next: " + new Date(nextDate));
    </code>
    problem is this code giving me same outputs, whereas, i need to supply, different timings to the same date.
    Thanks to anyone who can help me.

    I think the easier way is to use Calendar.getInstance() to return a Calendar instance and then use the various set() methods to set the time to midnight or the second before midnight of the next day.
    See the API docs for java.util.Calendar.
    - Saish

  • Problem inserting date into MS SQL Server

    I am trying insert date into MS SQL Server database. First I used Statement and when I insert the date only date used to be inserted properly and the time used to be always 12:00:00 AM. I tried PreparedStatement and when I insert I get an error message:
    SQL Error: [Microsoft][ODBC SQL Server Driver]Optional feature not implemented
    I have attached the code.
    GregorianCalendar cal = new GregorianCalendar();
    java.util.Date dtm = (java.util.Date)cal.getTime();
    SimpleDateFormat formatOb = new SimpleDateFormat("dd/MM/yy hh:mm:ss");
    String date= (String)formatOb.format(dtm);
    dateCreated = new java.sql.Date(formatOb.parse(date).getTime());
    PreparedStatement psmt = con.prepareStatement("INSERT INTO Resume (ResumeName, Summary, Skills, OtherInformation, Interests, Memberships, Languages, Category, DateCreated, SupervisorName) VALUES(?,?,?,?,?,?,?,?,?,?)");
    psmt.setString(1, name);
    psmt.setString(2, summary);
    psmt.setString(3, skills);
    psmt.setString(4, info);
    psmt.setString(5, interest);
    psmt.setString(6, member);
    psmt.setString(7, language);
    psmt.setString(8, category);
    psmt.setDate(9, dateCreated);
    psmt.setString(10, loginName);
    psmt.executeUpdate();
    Any suggestions will be really helpful.

    Thanks,
    I changed the field in the database of DateCreated to timestamp, but when I insert the some binary data is inserted into the database. something like 0000000000000017D.
    I installed jtds-0.8.1 driver from source forge. but when try to connect to the database I get an error as:
    Connection refused: connect
    Error: Connection refused: connect
    I have attached the code for setting the driver and url also.
    private String driver = "net.sourceforge.jtds.jdbc.Driver";
    private String url = "jdbc:jtds:sqlserver://TEKKATTE:1433/placement;TDS=7.0";

  • Date format /structure for JDBC

    Hi, can anyone tell be what format a date should be in when querying a database. I have some old code that was transfered to a new app server which follows Java standards very strictly. Now it gives me problems when comparing dates, for example a query that finds records for a date BETWEEN two other dates. The old format was dd-mon-yyyy, but this doesn't work anymore and neither does dd-mon-yy OR yyyy-mon-dd. When I do the query in the text editor(SQL Plus) it works, but not within the Java code.
    Any ideas?
    Thanks

    I see what you mean now. Yes, format matters then. Your HTML page will assume that the string that's typed into the text box will be a valid date string using a format that you choose.
    You should turn that String into a java.util.Date using java.text.DateFormat.parse(). Be sure to call setLenient(false) on the DateFormat instance before you call parse(). That way you'll get a java.text.ParseException if the String isn't valid according to your pattern and you can send an error page back to the client. (OR validate the pattern on the client side using JavaScript before the page is submitted.)
    Once you've got a valid java.util.Date for your DateFormat instance, create a java.sql.Date to pass to the ava.sql.PreparedStatement.setDate method.
    Warner's point is that by the time you get around to passing the java.sql.Date to PreparedStatement, all that validation stuff is supposed to be done.

Maybe you are looking for

  • How do I share photos from iPhone to Mac over wifi?

    I have a 2014 MacBook Air newly upgraded to Yosemite, and a 5S also from earlier this year. I would like to send files (photos) from my own phone so they are files -- rather than sending them to iPhoto. I have been trying to figure out how to do this

  • HT1338 I am a student, and I purchased Logic Pro 9 nine or ten months ago, can I download a free upgrade to Logic Pro X?

    Hi, I am a student, and I purchased Logic Pro 9 nine or ten months ago, can I download a free upgrade to Logic Pro X? It seems I should be able to. If not, how much would it cost me? Does anybody know? Thank you, Michael McCarty

  • 6500 prints too small

    I have an All in One 6500 printer that I bought at Christmas time.  When printing anything online, (whether I highlight & print selection or print the whole webpage), the fonts and everything shrinks and is too small to read.  I have looked through t

  • Gmail integration does not work correctly

    I always had a working integration of my Gmail account. eMails were sent using gmail.com, every sent eMail was saved in the "Sent" folder. Three weeks ago, sent eMails did not appear in the "Sent" folder anymore, and eMails were mailed by srs.bis.eu.

  • Error when installing on macpro 1.1

    I'm running a mac pro 1.1 "Dual-Core intel Xeon" 2.66, when I try to install snow leopard server 10.6 I get an error.