天天看點

資料庫查詢錯誤

資料庫查詢錯誤

“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘by time desclimit 0,24’ at line 1”錯誤

資料庫查詢錯誤

運作javaweb項目時顯示如上圖的錯誤,控制台提示如下圖的錯誤

資料庫查詢錯誤

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘by time desclimit 0,24’ at line 1

它的意思是:你的SQL語句有錯誤,在’by time desclimit 0,24’ 附近,在第一行

原代碼如下:

"select a.productid,a.name productname,a.myprice,a.marketprice,a.storecount,a.hit,a.time,a.photo,a.categoryid,b.name categoryname from product a,category b where a.categoryid=b.categoryid" + orderby + "limit" + startIndex + "," + pageSize
           

更改後:

"select a.productid,a.name productname,a.myprice,a.marketprice,a.storecount,a.hit,a.time,a.photo,a.categoryid,b.name categoryname from product a,category b where a.categoryid=b.categoryid " + orderby + " limit " + startIndex + "," + pageSize
           

其實錯誤很簡單,就是在“orderby”參數的時候前後沒有添加空格,導緻資料庫查詢出錯,但是你在寫的時候不會報錯,至于在運作的時候控制台才會出現如圖的錯誤

繼續閱讀