Solved

Updating a oracle date type in a db?

Posted on 2001-06-21
7
261 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 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
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…
Suggested Courses

623 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