Error syntax in query with Postgresql JSP sort

Asked

Viewed 24 times

0

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

inserir a descrição da imagem aqui

 public List<Motoristas> mostrarMotoristasPaginado(int pagina,String ordenacao,String pesquisa){
    try {
        con = Conecta.conexao();
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Conecta.class.getName()).log(Level.SEVERE, null, ex);
    }


int limite=3;
int offset=(pagina*limite)-limite;



    try {

       String sql="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;
    }


}

1 answer

0


just put a gap between the 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 the syntax will be wrong anyway

Browser other questions tagged

You are not signed in. Login or sign up in order to post.