Solved

Updating a oracle date type in a db?

Posted on 2001-06-21
7
224 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 86
countAbc challenge 9 49
Java - Why doesn't this JFrame work 3 18
Java DateChooser? 2 11
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now