The SQL query work fine in MySQL database, but when i use the same query in JDBC, I get:
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 'Foods Ltd AND clsp_stockexchange=bse GROUP BY CLSP_DATEOFTRADE' at line 1
MySQL Version is 5.0. My jdbc code:
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);
}
I thing issue with where clause
WHERE clcm_nameofthecompany = ADF Foods Ltd
AND clsp_stockexchange=bse
GROUP BY CLSP_DATEOFTRADE
its need to wrap ADF Foods Ltd with quotation. as
WHERE clcm_nameofthecompany = 'ADF Foods Ltd'
AND clsp_stockexchange=bse
GROUP BY CLSP_DATEOFTRADE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With