SQL查询在MySQL数据库中运行良好,但是当我在JDBC中使用相同的查询时,我得到:
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在第1行'Foods Ltd AND clsp_stockexchange = bse GROUP BY CLSP_DATEOFTRADE'附近使用正确的语法
MySQL版本是5.0。我的jdbc代码:
Class.forName(driver).newInstance();
conn = DriverManager.getConnection(url+dbName,userName,password);
String query = "SELECT max(CLSP_DATEOFTRADE) AS TradeDate,CLSP_CLOSEPRICE FROM stock.clccompany1 LEFT JOIN stock.clsp1 ON clccompany1.clcm_clsm_keyid=clsp1.clsp_clcm_keyid WHERE clcm_nameofthecompany=ADF Foods Ltd AND clsp_stockexchange=bse GROUP BY CLSP_DATEOFTRADE";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(query);
while(rs.next())
{
String s1=rs.getString(1);
String s2=rs.getString(2);
out.print(s1);
out.print(s2);
}
答案 0 :(得分:1)
我在where子句
的问题WHERE clcm_nameofthecompany = ADF Foods Ltd
AND clsp_stockexchange=bse
GROUP BY CLSP_DATEOFTRADE
需要用报价包装ADF Foods Ltd。 如
WHERE clcm_nameofthecompany = 'ADF Foods Ltd'
AND clsp_stockexchange=bse
GROUP BY CLSP_DATEOFTRADE