使用ORDER和LIMIT时出现语法错误。我不熟悉mysql你能指出错误。
ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,"
+ "company_name from images,products"
+ "where images.product_name = products.product_name ORDER BY hits DESC LIMIT 5");
答案 0 :(得分:3)
问题是当您连接字符串时,products
和where
之间没有空格,因此查询最终看起来像
... from images,productswhere images.product_name = ...
为其中一个字符串添加空格:
ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,"
+ "company_name from images,products"
+ " where images.product_name = products.product_name ORDER BY hits DESC LIMIT 5");
您不会说出您正在使用的编程语言,但是许多允许字符串跨越行,因此您不需要连接。然后你可以写:
ps = con.prepareStatement("Select product_id,image_name,images.product_name,price,company_name
from images,products
where images.product_name = products.product_name
ORDER BY hits DESC LIMIT 5");