0

i got a table made in this way

CREATE TABLE WS_NAPACQ00T
( IDE_IDEN varchar2(20) PRIMARY KEY NOT NULL,
  CLB_CXML CLOB,
  SYS_DATE TIMESTAMP
);

and this java code to put in dt_date current date.

Timestamp dt_date = new Timestamp(System.currentTimeMillis());
String insertXML = "insert into WS_NAPACQ00T (IDE_IDEN, CLB_CXML, SYS_DATE) values ('10', 'test', '"+dt_date+"' ) ";
result = statement.executeQuery(insertXML);

the error is:

"not a valid month"

how can i resolve?

3
  • you need to convert the java timestamp into oracle timestamp format.. Commented Dec 1, 2014 at 11:59
  • how is possible convert from java timestamp into oracle timestamp? Commented Dec 1, 2014 at 12:02
  • 1
    Use a PreparedStatement (side benefit of protection against SQL injection) and call setTimestamp. Commented Dec 1, 2014 at 12:06

1 Answer 1

4

Don't use Statement it can lead to SQLInjection, instead use PreparedStatement as follows.

String insertXML = "insert into WS_NAPACQ00T (IDE_IDEN, CLB_CXML, SYS_DATE) values (?, ?, ?) ";
PreparedStatement statement = connection.prepareStatement(insertXML);
statement.setString(1,"10");
statement.setString(2,"test");
statement.setTimestamp(3, new Timestamp(System.currentTimeMillis()));
result = statement.executeQuery();

Unrelated.

If you want to insert current timestamp you can use CURRENT_TIMESTAMP. SELECT CURRENT_TIMESTAMP from DUAL; will give the current timestamp.

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, it runs well. but apart the security, i don't understand why with prepared statement it runs ok, but with normal statement it goes in error.
In normal statement you have to construct the query as you do in a SQL client like sqlplus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.