"java.sql.SQLException:@P0" 附近有错误

问题出现:  "java.sql.SQLException:@P0" 附近有错误,原因sql 不支持“select top ? from [table_name]” 这种语法

解决之道:

sql=“select top %s  from [table_name]”;
sql=String.format(sql,"20");

举一反三:

如有预处理的时候:select top %s * from [table_name] where userId<? and userage>?;

解决之道:

sql = select top %s * from [table_name] where userId<? and userage>?;
sql = String.format(sql,20);
PrepareStatem pst = con.getPrepareStatement();
pst.setint(1,100);
pst.setInt(2,20);
。。。。。。。。。


发布了16 篇原创文章 · 获赞 8 · 访问量 11万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章