Bom dia,
Fiz um cód que consigo inserir no postgres utilizando um campo do tipo bytea um pdf.
fiz bean está dessa forma.
private InputStream tutorial;
public InputStream getTutorial() {
return tutorial;
}
public void setTutorial(InputStream tutorial) {
this.tutorial = tutorial;
}
e cadastro o pdf da seguinte forma:
public boolean cadastraInstrumento(Instrumento ins) throws SQLException, FileNotFoundException {
try {
File file = new File("c:\\experimento\\tutorial\\thies.pdf");
FileInputStream fis = new FileInputStream(file);
stmt = con.prepareStatement("INSERT INTO instrumento(nserie,fabricante,equipamento,especificacao,diretorio,tutorial)VALUES(?,?,?,?,?,?)");
stmt.setString(1, ins.getNserie().toUpperCase());
stmt.setString(2,ins.getFabricante().toUpperCase());
stmt.setString(3,ins.getEquipamento().toUpperCase());
stmt.setString(4,ins.getEspecificacao().toUpperCase());
stmt.setString(5, ins.getDiretorio());
s[b]tmt.setBinaryStream(6, fis, (int)file.length()); [/b]
stmt.execute();
desconecta();
return true;
} catch (SQLException e) {
stmt = null;
e.printStackTrace();
return false;
}
}
ele está cadastrando certo!
Gostaria de saber como faço pra dar um select no banco pra trazer o campo onde está o pdf e no JSTL conseguir abrir o pdf, segue abaixo o cód.
public Instrumento exibedadosinstrumento(int idinstrumento){
try {
String sql = “SELECT * from instrumento WHERE idinstrumento = '” + idinstrumento + “’”;
//System.out.println(sql);
stmt = con.prepareStatement(sql);
rs = stmt.executeQuery();
while(rs.next()){
ins = new Instrumento();
ins.setIdinstrumento(rs.getInt(“idinstrumento”));
ins.setNserie(rs.getString(“nserie”));
ins.setFabricante(rs.getString(“fabricante”));
ins.setEquipamento(rs.getString(“equipamento”));
ins.setEspecificacao(rs.getString(“especificacao”));
ins.setDiretorio(rs.getString(“diretorio”));
ins.setTutorial(rs.getBinaryStream(“tutorial”));
}
} catch (SQLException e) {
e.printStackTrace();
}
return ins;
}
JSTL
<display:column sortable=“false” style=“width:30px” title=“Tutorial”>
<a href="<c:url value="${lista[item].tutorial}"></c:url>">
</display:column>
Ele imprimi apenas o endereço de memória.
Muito Obrigado