Solved

Updating a oracle date type in a db?

Posted on 2001-06-21
7
248 Views
Last Modified: 2011-09-20
Hi I'm currently trying to convert a java date type to a Oracle date type to update database information. I have created the code and it works perfect on SQL server 2000 (via an JDBC:ODBC connection) but encounters errors when I connect to an oracle 8 database. The code is as follows:

Date dtDate = new Date(System.currentTimeMillis ());

runNumber++;

strSQL = "insert into message (run_Number, message_Date) values (" + Long.toString (runNumber) +  " , '" + dtDate.toLocaleString() + "')";

I'm getting the following error message from oracle.:

java.sql.Exception: ORA-01830: date format picture ends before converting entire input string

What am I doing wrong..? Do I have to convert the value in a different form?
0
Comment
Question by:simlox
  • 4
  • 2
7 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 100 total points
ID: 6213579
You are probably better off doing this as a Prepared statement like so:

  PreparedStatement s = connection.prepareStatement( "INSERT INTO MESSAGE ( run_number, message_date ) values ( ?, ? )" );

  s.setString( 1, "" + runNumber ) ;
  s.setDate( 2, dtDate ) ;
  s.executeQuery() ;

Does that work?

Tim.
0
 
LVL 1

Expert Comment

by:tonus
ID: 6213587
what are the data type you used in oracle?

Convert the date to specfic format ie(yyyymmdd hh:mi:ss)and use
to_date(strDate,'yyyymmdd hh:mi:ss') without any quotes outside
0
 
LVL 35

Expert Comment

by:TimYates
ID: 6213609
If the date field is actually of type String, then of course using my scheme you can do:

  s.setString( 2, dtDate.toLocaleString() ) ;

but toLocaleString has been deprecated since JDK 1.2, and you should use DateFormat.format instead...  (if you are using JDK 1.2 or above)

Good Luck,

Tim.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:simlox
ID: 6214667
The datatype used in oracle is DATE
0
 
LVL 35

Expert Comment

by:TimYates
ID: 6214705
Have you tried my first comment then?

Does it not work?

Tim.
0
 

Author Comment

by:simlox
ID: 6215284
yep.. work fine.. thnaks
0
 
LVL 35

Expert Comment

by:TimYates
ID: 6215347
No worries :-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet doXXX methods 3 62
login jsp example 24 68
Html Table Looping (part 2) 5 28
web project error add remove 1 32
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question