Reputation: 2133
I have a SpringBoot app. that uses JdbcTemplate to connect to a SQL Server DB, using this syntax:
int numOfRowsAffected = remoteJdbcTemplate.update(
"insert into dbo.[ATRESMEDIA Resource Time Registr_] " +
"(Entry No_, Posting Date, Resource No_, Job No_, Work Type, Quantity, Unit of Measure, Description, Company Name, Created Date-Time ) " +
" VALUES (?,?,?,?,?,?,?,?,?,?);",
atresMediaTimeRegistr.getEntryNo(),
atresMediaTimeRegistr.getPostingDate(),
atresMediaTimeRegistr.getResourceNo(),
atresMediaTimeRegistr.getJobNo(),
atresMediaTimeRegistr.getWorkType(),
atresMediaTimeRegistr.getQuantity(),
atresMediaTimeRegistr.getUnitOfMeasure(),
atresMediaTimeRegistr.getDescription(),
atresMediaTimeRegistr.getCompanyName(),
atresMediaTimeRegistr.getCreatedDate());
But I got this error:
com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near 'No_'.
Upvotes: 0
Views: 208
Reputation: 17953
Your column names are with spaces, use square brackets []
for the column names like following.
int numOfRowsAffected = remoteJdbcTemplate.update(
"insert into dbo.[ATRESMEDIA Resource Time Registr_] " +
"([Entry No_], [Posting Date], [Resource No_], [Job No_], [Work Type], [Quantity], [Unit of Measure], [Description], [Company Name], [Created Date-Time] ) " +
" VALUES (?,?,?,?,?,?,?,?,?,?);",
For example if you try query like following in SQL
INSERT INTO TABLE1(Entry No_)
SELECT 1
You will get the same error.
Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'No_'.
Upvotes: 1