0

i have created a coloumn in sql database with timestamp database. and from java i am trying to run insert query given below

st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
st.executeUpdate("insert into profmessage values('" + uid + "','" + from + "','" + to + "','" + msg + "','" + dt + "',1,0,'" + new java.sql.Timestamp(new Date().getTime()) + "')");
st.close();

It is showing

sqlexception  inconsistent datatypes: expected TIMESTAMP got NUMBER
4
  • 4
    First thing to first: don't put values into SQL like that. Use a prepared statement. Next, specify the columns in your insert statement, to avoid it being schema-order-specific. Fix both of those issues, then see if it still doesn't work. Commented Jul 3, 2014 at 8:25
  • can you say SQL injection? Commented Jul 3, 2014 at 8:25
  • 1
    your issue must be related to columns ordering, use column name in insert statement also as suggested by Jon you should use prepared statement Commented Jul 3, 2014 at 8:27
  • @coreJavare u r right. I was wrong woth coloumn order. Nut now it is giving exception as ORA-01843: not a valid month Commented Jul 3, 2014 at 8:32

2 Answers 2

2

I think you should use PreparedStatement (which is also good for avoiding SQL injections), and insert the value of timestamp like this:

preparedStatement.setTimestamp(theNumberOfTimestampOccurenceInYourQery, new java.sql.Timestamp(new Date().getTime()));
Sign up to request clarification or add additional context in comments.

Comments

0

In SQL Server, the TIMESTAMP data type doesn't mean what you think it means. TIMESTAMP columns are meant to be updated by the server itself as it creates and updates rows. Their values look like "0x00000000001CF9F9", which is really just a number in hexadecimal format.

What you need is the DATETIME data type.

2 Comments

The ORA-01843 error code mentioned in the comments suggests they're not using SQL Server.
This is Oracle, not SQL Server... Yeah, never mind my answer, it's not applicable. I'll leave it up in case someone else googles the problem, but in the future, I would use better question tagging!

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.