public ArrayList<DocumentsDetails> getDocumentsDetails(String personnelID) { ArrayList<DocumentsDetails> docList = new ArrayList<>(); PreparedStatement ps; ResultSet rs; if (dbc.connect()) { try { String sqlQuery = "select " + DOC_COLUMN + " from " + DOC_INFO + " where MaNV = '" + personnelID + "'"; ps = dbc.getConnection().prepareStatement(sqlQuery); rs = ps.executeQuery(); while (rs.next()) { DocumentsDetails doc = new DocumentsDetails(); doc.setName(rs.getNString(1)); doc.setSaveDate(rs.getDate(2)); doc.setFile(rs.getBytes(3)); doc.setExtension(rs.getString(4)); doc.setKindID(rs.getShort(5)); doc.setID_IDENTITY(rs.getShort(6)); docList.add(doc); } } catch (SQLException ex) { Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex); } } return docList; }
public boolean insertDocumentDetails(String personnelID, DocumentsDetails doc) { boolean check = true; PreparedStatement ps; if (dbc.connect()) { try { String sqlQuery = "INSERT INTO " + DOC_INFO + " VALUES(?,?,?,?,?,?)"; ps = dbc.getConnection().prepareStatement(sqlQuery); ps.setString(1, personnelID); ps.setNString(2, doc.getName()); if (doc.getSaveDate() == null) { ps.setNull(3, java.sql.Types.DATE); } else { ps.setDate(3, doc.getSaveDate()); } ps.setBytes(4, doc.getFile()); ps.setString(5, doc.getExtension()); ps.setShort(6, doc.getKindID()); if (ps.executeUpdate() < 1) { check = false; } } catch (SQLException ex) { Logger.getLogger(PersonnelDAO.class.getName()).log(Level.SEVERE, null, ex); } } return check; }