Solved

Updating a oracle date type in a db?

Posted on 2001-06-21
7
256 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Restore security prompts not working 10 270
going to wrong jsp page 2 71
Using jdbcTemplate.batchUpdate to improve INSERT performance 6 35
Bitwise and to sum elements 2 55
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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
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:
Suggested Courses

752 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