JDBCサンプル

public void insertBookInfo(BookInfoDTO bookInfoDTO) throws SQLException {

int count = 0;
Connection conn = DataSourceManager.getInstance().getConnection();

try {
PreparedStatement statement = conn.prepareStatement(insert);
statement.setString(1,bookInfoDTO.getIsbn());
statement.setString(2,bookInfoDTO.getCategory().getCategoryId());
statement.setString(3,bookInfoDTO.getTitle());
statement.setString(4,bookInfoDTO.getAuthor());
statement.setTimestamp(5,bookInfoDTO.getPublicationDate());
statement.setInt(6,bookInfoDTO.getPrice());
statement.setString(7,bookInfoDTO.getContent()); 

count = statement.executeUpdate();

if(count == 0) {
throw new SQLException();
}

conn.commit();

} catch (SQLException e) {
if(conn != null) {
conn.rollback();

}
} finally {
if(conn != null) {
conn.close();
}
}
}