0

I'm trying to add a DATETIME value to the SQL database from Java. Actually I load the java.sql.Date object to an object array and then load the value into the prepared statement from the array.

This is my code:

java.util.Calendar cal = java.util.Calendar.getInstance();
java.sql.Date timestamp = new java.sql.Date(cal.getTimeInMillis());
values[0] = timestamp;

This is the exception that I am getting when I run the code:

 com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'UPDATE_DATE'.
Stack trace:com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'UPDATE_DATE'.

UPDATE_DATE is the column name in the table. Kindly help me out in this.

EDIT : This is the query:

INSERT INTO EXAMPLETABLE VALUES UPDATE_DATE=?,CONT_STATUS_NEW_ID=?,CONT_STATUS_DESC=?,LOCATION_ID=?,READ_STATUS=?,CONT_TYPE_ID=?,CONT_TYPE_DESC=?,CONT_ID=?

This is where the exception is thrown:

((PreparedStatementDataTarget) insertTarget).executeUpdate(values,arguments);

Actually you can't get anything out of the execute statement since it implements a lot of classes and custom methods. If there is anything wrong , then it should be in the logic which I use to add the date to the Object array (values) .

3
  • Show us the line where it is throwing the exception. Show your update query. Commented Jun 30, 2015 at 7:55
  • @codeaholicguy added query! Commented Jun 30, 2015 at 8:55
  • @PrerakSola added prepared statment part and query Commented Jun 30, 2015 at 8:55

1 Answer 1

3

You are mixing insert and update syntax. You should either use

INSERT INTO tableName [(column list)] VALUES (values list)

Or

UPDATE tableName
SET column = value 
[, column = value]
[WHERE condition]

Note #1: square brackets mean the part inside is optional.
Note #2: column list stands for column names delimited by a comma, values list stands for values delimited by a comma.

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

4 Comments

That is not UPDATE . It is UPDATE_DATE=? .. It is one of the columns.
Do you want to insert a new record or update vlaues in an existing one?
Then use the correct insert syntax: insert into tableName (column1, column2) values (?,?)
Yup that was the issue . Thanks.

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.