Syntax error in query with ordering PostgreSQL JSP

0

I made a select in the database in which it will make a query according to name, and it orders it but when executing the select the following error occurred.

publicList<Motoristas>mostrarMotoristasPaginado(intpagina,Stringordenacao,Stringpesquisa){try{con=Conecta.conexao();}catch(ClassNotFoundExceptionex){Logger.getLogger(Conecta.class.getName()).log(Level.SEVERE,null,ex);}intlimite=3;intoffset=(pagina*limite)-limite;try{Stringsql="Select * from tb_motorista where mo_nome like '%"+pesquisa+"%' order by"+ordenacao+" LIMIT 3 OFFSET"+offset;
        Statement statement = con.createStatement();     

    ResultSet rs = statement.executeQuery(sql); 
      List lista = new ArrayList(); 


        while(rs.next()){
             Motoristas mo= new Motoristas();
            mo.setMo_nome((rs.getString("mo_nome")));
            mo.setMo_data(rs.getString("mo_data"));
            mo.setMo_cpf(rs.getString("mo_cpf"));
            mo.setMo_modelo(rs.getString("mo_modelo"));
            mo.setMo_status(rs.getString("mo_status"));
            mo.setMo_sexo(rs.getString("mo_sexo"));


           lista.add(mo);

        }

        return lista;
    } catch (Exception e) {
        JOptionPane.showConfirmDialog(null,e);
        return null;
    }


}
    
asked by anonymous 13.09.2017 / 23:44

1 answer

0

Just put a space between by and its variable:

String sql="Select * from tb_motorista where mo_nome like '%"+pesquisa+"%' order by "+ordenacao+" LIMIT 3 OFFSET"+offset;

because order bynomecompleto syntax will be wrong even

    
14.09.2017 / 00:01