Reputation: 2231
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) .
Upvotes: 0
Views: 427
Reputation: 82474
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.
Upvotes: 3