I have an android application that connects to a database through JDBC, and when making a query with top 1, it gives me the following error:
java.sql,SQLEXCEPTION: use of the execute query(String) method is not supported on this type of statement
and this is the query in question
select top 1 * from reporte where nombre_ruta = 'nombre_ruta' order by fecha desc;
the query in the database works perfectly, I hope you can guide me :)
the code is the following:
try {
String query = "select top 1 nombre_ruta,descripcion from reporte where nombre_ruta = '"+marker.getTitle()+"';";
con = connectionclass (un, passwords, db, ip);
if (con == null) {
isConnected(getApplicationContext());
} else {
stmt = con.prepareStatement(query);
stmt.setQueryTimeout(1);
rs=stmt.executeQuery(query);
while (rs.next()) {
reporte = rs.getString("nombre_ruta");
descripcion=rs.getString("descripcion");
}
Since you're using a
PreparedStatement
, you shouldn't pass the parameterquery
to the call:The call should be simply (no parameters):