简体   繁体   中英

Sql Server JDBC Driver Error

When I am trying to set preparestament parameter dynamically based on parameter count like below, SQL server JDBC driver give me error.

preparedStatement = root.prepareStatement("SELECT * FROM users WHERE DATE BETWEEN ? AND ?");
if(preparedStatement.getParameterMetaData()!=null){ //exception at this line

//do some logic
}

Error :

com.microsoft.sqlserver.jdbc.SQLServerException: com.microsoft.sqlserver.jdbc.SQLServerException: Incorrect syntax near the keyword 'BETWEEN'.

Same Code works fine for Mysql jdbc driver.

(I am using sqljdbc41.jar for mssql).

Can any one have this kind of issue or any solution?

DATE是保留字,您需要将其用引号引起来:

root.prepareStatement("SELECT * FROM users WHERE \"DATE\" BETWEEN ? AND ?");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM