Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle JDBC Timestamp error - ORA-01841

Re: Oracle JDBC Timestamp error - ORA-01841

From: Frank van Bortel <fvanbortel_at_netscape.net>
Date: Fri, 14 May 2004 23:12:46 +0200
Message-ID: <c83ci2$mja$1@news4.tilbu1.nb.home.nl>


Luch wrote:

> I'm using the JDBC driver that came with Oracle 9 release 2. I've
> tried both the classes12 and classes 11, and using the parameter:
> -Doracle.jdbc.V8Compatibility="true"
>
>
> I get this error when trying to insert a Java timestamp into an oracle
> date field: java.sql.SQLException: ORA-01841: (full) year must be
> between -4713 and +9999, and not be 0
>
>
> The thing is, I'm trying a JDO implementation which requires this to
> work. Does anyone know of this issue? Here is the program code:
>
>
>
>
>
> import java.sql.PreparedStatement;
> import java.sql.*;
> import java.util.*;
> import java.sql.Timestamp;
>
>
> public class JDBCTime2
> {
> public static void main(String[] args) throws Exception {
> String driverName = "oracle.jdbc.driver.OracleDriver";
> String url = "jdbc:oracle:thin:@duke:1521:trax";
> String user = "odb";
> String pass = "odb";
>
> Class driverClass = Class.forName (driverName);
> Driver driver = DriverManager.getDriver (url);
> Properties props = new Properties ();
> props.setProperty ("user", user);
> props.setProperty ("password", pass);
> Connection c = driver.connect (url, props);
>
>
> try {
> // drop the test table, in case it exists
>
> //-- new stuff below -------
>
> PreparedStatement ps = c.prepareStatement("INSERT INTO
> ODB.AC_ACTUAL_FLIGHTS(AC, CREATED_BY, CREATED_DATE, FLIGHT_LEG,
> FLIGHT_LOG) VALUES (?, ?, ?, ?, ?)");
> ps.setString(1, "J-TRAX");
> ps.setString(2, "INTERFACE");
> Timestamp t = new
> java.sql.Timestamp(System.currentTimeMillis());
> System.out.println(t);
> ps.setTimestamp(3, t, null);
> ps.setInt(4, 2);
> ps.setString(5, "383282");
> int rows = ps.executeUpdate();
>
> System.out.println("UPDATE:" + rows);
> ps.close();
>
> //!--- end new stuff --
> }
> catch (Exception e) {
> e.printStackTrace();
> }
>
> c.commit();
>
> }
> }

No idea what you try to do, but:
1) timestamps are V9+, and you have V8compatibility=true. 2) Most ORA-01841 errors have to do with the session time

    format; try an explicit
   alter session set nls_date_format=......

-- 

Regards,
Frank van Bortel
Received on Fri May 14 2004 - 16:12:46 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US