execute query TOP 1, JDBC

1

I have an application on android that connects to a database through JDBC, and when making a query with top 1, I get the following error:

  

java.sql, SQLEXCEPTION: use of the execute query (String) method is not supported on this type of stament

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 as follows:

    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");
    }
    
asked by zhet 13.12.2016 в 03:03
source

1 answer

0

Since you are using PreparedStatement , you should not pass the query parameter to the call:

stmt.executeQuery(query);

The call should be simply (without parameters):

stmt.executeQuery();
    
answered by 13.12.2016 / 03:16
source