Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Updating a oracle date type in a db?

Posted on 2001-06-21
7
Medium Priority
?
265 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 400 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

688 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