You are on page 1of 1

String filePath = "D:/Photos/Tom.

jpg";
InputStream inputStream = new FileInputStream(new File(filePath));
String sql = "INSERT INTO person (photo) values (?)";
PreparedStatement statement = connection.prepareStatement(sql);
statement.setBlob(1, inputStream);
statement.executeUpdate();
InputStream is;
...
File image = fileChooser.getSelectedFiile();
...
preparedStatement.setBlob( index, is = new FileInputStream( image ) );
...
} finally {
is.close();
preparedStatement.close();
connection.close();

You might also like