Olá pessoal, uma coisa estranha que me aconteceu quando estava usando um campo tipo bytea (blob) no postgresql, quando executei o código:
public byte[] getFoto() {
String SQL="select foto from alunos where id_aluno="+aluno.getId()+"; ";
try{
Statement stmt = conexao.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
if (rs.next()) {
Blob blob = rs.getBlob("foto");
byte[] bytes = blob.getBytes(1,(int)blob.length());
return (bytes);
}
else {
return (null);
}
}
catch (NullPointerException e) {
return (null);
}
catch (SQLException e) {
return (null);
}
}
Daí levantou uma exceção ?SQLException? com a seguinte mensagem: Valor inválido para tipo int : \377\330\377\340 … e o resto do binário
Mudei para o a seguir e tudo funcionou. Isso já aconteceu com alguém?
public byte[] getFoto() {
String SQL="select foto from alunos where id_aluno="+aluno.getId()+"; ";
try{
Statement stmt = conexao.createStatement();
ResultSet rs = stmt.executeQuery(SQL);
if (rs.next()) {
byte[] bytes = rs.getBytes("foto");
return (bytes);
}
else {
return (null);
}
}
catch (NullPointerException e) {
return (null);
}
catch (SQLException e) {
return (null);
}
}