"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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章