I'm tring to write a query but I obtain a syntax error. I know that this error is in the query's syntax. This is the query
ResultSet set=statement.executeQuery("Select * from Ombrellone where PosizioneX='"+c.getX()+"',PosizioneY='"+c.getY()+"'" );
Anyone can help me?
Suresh Atta
122k38 gold badges207 silver badges315 bronze badges
asked Oct 15, 2014 at 15:00
doflamingo
771 gold badge1 silver badge9 bronze badges
2 Answers 2
If you want to have multiple conditions on select, you must use AND, not comma.
ResultSet set=statement.executeQuery("Select * from Ombrellone where PosizioneX='"+c.getX()+"' and PosizioneY='"+c.getY()+"'" );
answered Oct 15, 2014 at 15:03
Suresh Atta
122k38 gold badges207 silver badges315 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Though the problem in your case was basically because you used comma on your SQL query which is wrong you can use AND or OR for condition fulfillment when using WHERE clause but also I would suggest you to use PreparedStatement over Statement.
String query = "Select * from Ombrellone where PosizioneX = ? and PosizioneY = ?"
PreparedStatement statement = conn.prepareStatement(query);
statement.setString(1,c.getX());
statement.setString(2,c.getY());
ResultSet resultSet = statement.executeQuery();
answered Oct 15, 2014 at 15:12
SparkOn
8,9665 gold badges31 silver badges36 bronze badges
default
PreparedStatement