I have a SQL query in java and I need to sort by name, but because of the issue of single and double quotes, it's not clear to me if I'm doing it right.
The code is the following:
public ArrayList paisesEnUnContinente (int id) {
ArrayList<Pais> data = new ArrayList();
try {
Statement orden = conn.createStatement();
ResultSet res;
res = orden.executeQuery("SELECT * FROM pais WHERE IdContinente = " + id +"' order by Nombre");
while (res.next()) {
Pais p = new Pais();
p.setIdCont(res.getInt("IdContinente"));
p.setNombrePais(res.getString("Nombre"));
p.setMillonesHab(res.getInt("Millones_habitantes"));
data.add(p);
}
orden.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, e);
}
return data;
}
That's ok, you just have a spare single quote before the
order
.