Calling stored procedures from Java

后端 未结 2 1696
迷失自我
迷失自我 2021-01-22 18:55

I\'m trying to call a mySQL stored procedure from my Java application. When I call the stored procedure from mySQL workbench, it works and I get the correct number of rows depen

2条回答
  •  迷失自我
    2021-01-22 19:09

    public void mostrarDatos() 
    {
        try {
            Connection con = null;
            con = getConnection();
    
            CallableStatement cs;
            cs = con.prepareCall("{CALL comprobarUsuario(?,?,?)}");
            cs.setString(1,"Jorge" );
            cs.setString(2, "1627Jorge");
            cs.registerOutParameter(3, Type.INT);
            cs.execute();
            ResultSet rs2 = cs.getResultSet();
    
            if(rs2.next()){
                System.out.println(true);
            }
            int resultado = cs.getInt(3); // check whether the column name is correct
            System.out.println(resultado);
            con.close();
    
        } catch (Exception e) {
    
        }
    }
    

提交回复
热议问题