Trouble getting hours, mins, secs to store in Oracle
From: Ed (ed.barrett_at_bigfoot.com)
Date: 12/11/03
- Next message: Paul Cooper: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Previous message: Kyuu: "Re: Oracle Databases' list"
- Next in thread: Paul Cooper: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Reply: Paul Cooper: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Reply: Andree Große: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Reply: Jeff Smith: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 11 Dec 2003 05:00:56 -0800
Folks,
I really hope I am doing something wrong here as it is driving me
nuts.
I have a database table defined as follows:
CREATE TABLE "Foo" ("Col1" NUMBER(10) NOT NULL, "Col2" VARCHAR2(100)
NOT NULL, "Col3" NUMBER(10) NOT NULL, "StartTime" DATE NOT NULL,
CONSTRAINT "PK_Foo" PRIMARY KEY ("Col1", "Col2", "Col3") );
I am trying to store a "date" field in it which will contain year,
month, day, hour, min and seconds.
I first of all tried to use a java.sql.Date yet quickly moved onto
java.sql.Timestamp
My code is as follows:
sqlTS = new java.sql.Timestamp(startTime.getTime());
System.out.println("TSvalue is " + sqlTS); // this prints correctly
// write and commit each row individually
startStmt.setInt(1,col1);
startStmt.setString(2,col2);
startStmt.setInt(3,col3);
startStmt.setTimestamp(4,sqlTS);
int rows = startStmt.executeUpdate();
if (rows != 1)
{
throw new Exception("ERROR inserting start row into
database. Expected 1 row but " + rows +
" rows were actually inserted");
}
conn.commit();
The code runs correctly and sure enough I have a row in the table.
Yet the following SQL:
select to_date("StartTime", 'DD MM YYYY HH24:MI:SS') from "Foo";
returns just:
11-DEC-03
I have tried sql.Date as well with the same results.
I am using Oracle 8.1.7 and the thin jdbc driver on Windows.
Any suggestions would be gratefully received - this is very
frustrating!!
Thanks
Ed
- Next message: Paul Cooper: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Previous message: Kyuu: "Re: Oracle Databases' list"
- Next in thread: Paul Cooper: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Reply: Paul Cooper: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Reply: Andree Große: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Reply: Jeff Smith: "Re: Trouble getting hours, mins, secs to store in Oracle"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|