This code takes picture test.gif and puts the picture bit value into a bytea coloumn.
public void addImage() throws SQLException, IOException {
Connection con = openConnection();
File file = new File("test.gif");
FileInputStream fis = new FileInputStream(file);
PreparedStatement ps = con.prepareStatement("INSERT INTO image VALUES (?, ?, ?)");
ps.setString(1, file.getName());
ps.setBinaryStream(2, fis, (int)file.length());
ps.setInt(3,1);
ps.executeUpdate();
fis.close();
}
My next goal is to display the picture that is saved in the database in bytes. How can this be done ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…