SQLite with java, error

-1

I have made a Database of Bank Accounts of a Bank, each of these accounts has its id to identify, and has its tipo , to know what type of account the user is accessing at that moment , type, it can have a current account and salary, are two types of accounts associated with this, so I want to search my bank using the account id and the type that is integer as well, but it is giving error. >

Banco Conta = new Banco();

Conta.conectar();

ResultSet resultSet = null;
PreparedStatement preparedStatement = null;

String sql = "SELECT *FROM Contas WHERE NumeroConta = ? "
        + " AND Tipo = ?";

try{
    preparedStatement = Conta.criarPreparedStatement(sql);
    preparedStatement.setInt(1, getNumConta());
    preparedStatement.setInt(5, getTipo());

    resultSet = preparedStatement.executeQuery();

    while(resultSet.next()){
        System.out.println(" " + resultSet.getFloat("Saldo"));
    }

}catch(SQLException e){
    e.printStackTrace();
}finally{
    try{
        resultSet.close();
        preparedStatement.close();
        Conta.desconectar();
    }catch(SQLException ex){
        ex.printStackTrace();
    }
}

This is the error:

Exception in thread "main" java.lang.NullPointerException
    at Usa.Busca.Trans(Busca.java:135)
    at Principal.main(Principal.java:82)
/home/nathan/.cache/netbeans/8.2/executor-snippets/run.xml:53: Java returned: 1
    
asked by anonymous 13.06.2018 / 21:43

1 answer

2

Try changing this line:

preparedStatement.setInt(5, getTipo());

To:

preparedStatement.setInt(2, getTipo());

Since in your sentence you have only 2 parameters and you are jumping from 1 to 5.

    
13.06.2018 / 22:40