int rows = 0;
FileInputStream fin = null;
ResultSet rslt = null;
Statement stmt = null;
PreparedStatement pstmt = null;
Blob photo = null;
long person_id = 1;
try {
conn.setAutoCommit(false);
// get Tim's photo
stmt = conn.createStatement();
rslt = stmt.executeQuery(
"select photo " +
"from person p, person_information i " +
"where p.person_id = i.person_id " +
"and last_name = 'O''Reilly' " +
"and first_name = 'Tim'");
rslt.next();
photo = rslt.getBlob(1);
rslt.close();
rslt = null;
stmt.close();
stmt = null;
// set up the update statement
pstmt = conn.prepareStatement(
"insert into person_information " +
"( person_id, biography, photo ) " +
"values " +
"( ?, empty_clob(), ? )");
// update the database
pstmt.setLong(1, person_id);
pstmt.setBlob(2, photo);
rows = pstmt.executeUpdate();
System.out.println(rows + " rows updated");
conn.commit();
pstmt.close();
pstmt = null;
}
catch (SQLException e) {
System.err.println("SQL Error: " + e.getMessage());
}
finally {
if (rslt != null)
try { rslt.close(); } catch (SQLException ignore) { }
if (stmt != null)
try { stmt.close(); } catch (SQLException ignore) { }
if (pstmt != null)
try { pstmt.close(); } catch (SQLException ignore) { }
}