469,917 Members | 1,642 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Date conversion from string to Oracle in jdbc

3
I am trying to convert a date from string format into the SQL date format. This seems to work fine as it prints out as 1999-01-01 - see code below. I then try to insert this as a variable into my table and I get the error:

ORA-01858: a non-numeric character found where a digit was expected.

Any help would be greatly appreciated

[code]
try
{
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("DD/MM/yy");
String s = "01/02/99";
java.util.Date utilDate = df.parse(s);
sqlDate = new java.sql.Date(utilDate.getTime());
System.out.println("SQL Date" +sqlDate); //1999-01-01
}
catch(ParseException p)
{
p.printStackTrace();
}

select = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,ResultSet.CONCUR_UPDATABLE);
System.out.println("In InsertRecord method");

// String updateStatement = "insert into video values (" +"'" + vid + "'," +"'" + title + "'," + "'" + type + "','" +sqlDate +"'," + vcharge +")";
int x = select.executeUpdate("INSERT INTO Video " + "VALUES ('M0009', 'Pokemon','U', 'sqlDate', 3.00)" );
System.out.println(x + " rows affected");

[code]
Feb 28 '07 #1
5 5000
r035198x
13,262 8TB
I am trying to convert a date from string format into the SQL date format. This seems to work fine as it prints out as 1999-01-01 - see code below. I then try to insert this as a variable into my table and I get the error:

ORA-01858: a non-numeric character found where a digit was expected.

Any help would be greatly appreciated

[code]
try
{
java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("DD/MM/yy");
String s = "01/02/99";
java.util.Date utilDate = df.parse(s);
sqlDate = new java.sql.Date(utilDate.getTime());
System.out.println("SQL Date" +sqlDate); //1999-01-01
}
catch(ParseException p)
{
p.printStackTrace();
}

select = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITI VE,ResultSet.CONCUR_UPDATABLE);
System.out.println("In InsertRecord method");

// String updateStatement = "insert into video values (" +"'" + vid + "'," +"'" + title + "'," + "'" + type + "','" +sqlDate +"'," + vcharge +")";
int x = select.executeUpdate("INSERT INTO Video " + "VALUES ('M0009', 'Pokemon','U', 'sqlDate', 3.00)" );
System.out.println(x + " rows affected");

[code]
What are the data types of your table in the database and what values are you trying to insert into that table.
Mar 1 '07 #2
pmagee
3
What are the data types of your table in the database and what values are you trying to insert into that table.
The datatypes of my table are VARCHAR2, VARCHAR2, VARCHAR2, DATE, NUMBER. I am entering data values from my Swing interface using 5 textfields.
Thanks
Mar 1 '07 #3
r035198x
13,262 8TB
The datatypes of my table are VARCHAR2, VARCHAR2, VARCHAR2, DATE, NUMBER. I am entering data values from my Swing interface using 5 textfields.
Thanks
Now post the exact sql statement that is giving you the error.
Mar 1 '07 #4
pmagee
3
Now post the exact sql statement that is giving you the error.
The following line in my java program compiles fine but the insert of the date into the table is giving me the error.
[code] int x = select.executeUpdate("INSERT INTO Video " + "VALUES ('M0009', 'Pokemon','U', 'sqlDate', 3.00)" ); [code]
You will see from my earlier code that I have converted the date from a string into the sqlDate format. My problem is that when I print it out to the console after the conversion it looks like 1999-01-01 but oracle is trying to store it as 01-JAN-99.

I am now trying to use TO_DATE(sqlDate, "DD-MON-YY) but I dont know how to put this in as a parameter into the executeUpdate() method. It's giving me an "unclosed character literal error".
Thanks.
Mar 1 '07 #5
r035198x
13,262 8TB
The following line in my java program compiles fine but the insert of the date into the table is giving me the error.
[code] int x = select.executeUpdate("INSERT INTO Video " + "VALUES ('M0009', 'Pokemon','U', 'sqlDate', 3.00)" ); [code]
You will see from my earlier code that I have converted the date from a string into the sqlDate format. My problem is that when I print it out to the console after the conversion it looks like 1999-01-01 but oracle is trying to store it as 01-JAN-99.

I am now trying to use TO_DATE(sqlDate, "DD-MON-YY) but I dont know how to put this in as a parameter into the executeUpdate() method. It's giving me an "unclosed character literal error".
Thanks.
I don't think it's the date that's giving you problems. I think it's the last field but you are supplying 3.00 which must be accepted unless if that field is taking integers only. Did you try 3 instead of 3.00?
Mar 1 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by owen | last post: by
9 posts views Thread by Kenevel | last post: by
reply views Thread by Rauf Sarwar | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.