I need to get the integer[] value, from an column named "jogos" in PostgreSQL, and store it in a int[] attribute in Java, but the resultSet.getArray show me this error:
incompatible types: Array cannot be converted to int[]
And there's no resultSet.getIntegerArray or something like that.
My function:
public ResultSet LogarUsuario(Usuario usuario){
String sql = "Select * FROM usuario WHERE email = '" + usuario.email + "' AND senha = '" + usuario.senha + "'";
try {
ResultSet rs = db.ExecutaBusca(sql); //search on DB and returns the result
usuario.setId(rs.getInt("id"));
usuario.setEmail(rs.getString("email"));
usuario.setSenha(rs.getString("senha"));
usuario.setJogos(rs.getArray("jogos")); //Line where is the problem
return rs;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
My class I will instantiate and store those values from DB:
public class Usuario {
public int id;
public String email;
public String senha;
public int[] jogos;
}
So, how can I get this integer[] value and store in a int[] attribute?
There's more code I guess is not needed, but I can send a specific part if requested.
It's my first question here, sorry if something it's confusing. Also, sorry if my english looks weird or wrong, I am still learning.
ResultSet.getArray()returns object of type interfacejava.sql.Array. You can use ResultSet.getArray().getArray() to get the java arrayincompatible types: Object cannot be converted to int[]