Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private String sqlStatement = "INSERT INTO Person VALUES(?,?)";
- public boolean insertMember(Object newMember) {
- Connection con = null;
- PreparedStatement ps = null;
- try {
- con = OracleDAOFactory.getConnection();
- ps = con.prepareStatement(sqlStatement);
- ps.setInt(1, newMember.getAttribute());
- ps.setString(2, newMember.getAnotherAttribute());
- ps.executeUpdate();
- System.out.println("Member inserted successfully.");
- return true;
- }
- catch (SQLException ex) {
- Logger.getLogger(NameOfClass.class.getName()).log(Level.SEVERE, null, ex);
- return false;
- }
- finally {
- if (con != null) {
- try {
- con.close();
- }
- catch (SQLException ex) {
- Logger.getLogger(NameOfClass.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment