@Override public boolean update(DamageItem d) throws Exception { String sql = "update damaged set item = ?, qty = ?, reason = ? , date = ? , staffStamp = ? where id = " + d.getId(); try { con = db.getConnect(); PreparedStatement statement = (PreparedStatement) con.prepareStatement(sql); statement.setString(1, d.getItem()); statement.setInt(2, d.getQty()); statement.setString(3, d.getReason()); statement.setString(4, d.getDate()); statement.setString(5, d.getStaffstamp()); statement.executeUpdate(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
// to implement public void add(Funcionario funcionario) { String sql = "INSERT INTO Funcionario (nome_funcionario, especialidade, comissao) VALUES (?, ?, ?)"; // String sqlNumFunc = "SELECT id_funcionario FROM Funcionario WHERE nome_funcionario = '?'"; try { PreparedStatement stmt = (PreparedStatement) connection.prepareStatement(sql); stmt.setString(1, funcionario.getNomeFuncionario()); stmt.setString(2, funcionario.getEspecialidade()); stmt.setDouble(3, funcionario.getComissao()); stmt.execute(); // stmt = (PreparedStatement) connection.prepareStatement(sqlNumFunc); // stmt.execute(); // ResultSet rs = stmt.executeQuery(); // funcionario.setNumFuncionario(rs.); stmt.close(); System.out.println("Funcionario Inserted Successfully"); } catch (SQLException e) { throw new RuntimeException(e); } }
/** * @param issueNumber * @param fast3CountList * @throws SQLException 四码预测插入预测计划方法 */ private void insertData2Db(String issueNumber, List<Fast3Count> fast3CountList) throws SQLException { Connection conn = ConnectSrcDb.getSrcConnection(); String sql = "insert into " + App.simaTbName + " (YUCE_ISSUE_START,YUCE_ISSUE_STOP,DROWN_PLAN,CREATE_TIME) values(?,?,?,?)"; String code1 = App.getNextIssueByCurrentIssue(issueNumber); String code2 = App.getNextIssueByCurrentIssue(code1); String code3 = App.getNextIssueByCurrentIssue(code2); int[] numArr = { fast3CountList.get(0).getNumber(), fast3CountList.get(1).getNumber(), fast3CountList.get(2).getNumber(), fast3CountList.get(3).getNumber() }; Arrays.sort(numArr); PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql); pstmt.setString(1, code1); pstmt.setString(2, code3); pstmt.setString( 3, Integer.toString(numArr[0]) + Integer.toString(numArr[1]) + Integer.toString(numArr[2]) + Integer.toString(numArr[3])); pstmt.setTimestamp(4, new java.sql.Timestamp(new Date().getTime())); pstmt.executeUpdate(); }
private void validateAdd(RentalSchema p) { // TODO: Aqui se anade la data a la tabla de RentMovie try { String query = "INSERT INTO rentmovie (MoviesID, CustomersID, Rented, RentedOn, ReturnedOn)" + "VALUES (?, ?, ?, ?, ?)"; //////////// Class.forName("com.mysql.jdbc.Driver"); // MySQL database connection Connection conn = (Connection) DriverManager.getConnection( "jdbc:mysql://us-cdbr-azure-east-a.cloudapp.net:3306/movierental?" + "user=b80812adafee28&password=5b6f9d25"); PreparedStatement pst = (PreparedStatement) conn.prepareStatement(query); ////////////////////////////// pst.setInt(1, p.getMoviesId()); pst.setInt(2, p.getCustomersId()); pst.setBoolean(3, true); pst.setString(4, p.getRentedOn()); pst.setString(5, "Not yet Returned!"); JOptionPane.showMessageDialog(null, "Data was saved sccessfully"); pst.executeUpdate(); conn.close(); } catch (ClassNotFoundException | SQLException e) { JOptionPane.showMessageDialog( null, "There was some problem with the connection. Please try again!"); e.printStackTrace(); } }
// TODO public int insertCert(ApkBean apk) { int ret = -1; for (CertBean cert : apk.certs) { try { PreparedStatement pstmt = null; String marketUpdateQuery = "INSERT INTO cert " + "(issuer,certhash,certBrief)" + " VALUES(?, ?,?) "; pstmt = (PreparedStatement) conn.prepareStatement(marketUpdateQuery); pstmt.setString( 1, ((X509Certificate) cert.certificate).getIssuerX500Principal().toString()); pstmt.setString(2, cert.certificateHash); pstmt.setString(3, apk.certInfo()); pstmt.executeUpdate(); ret = 0; } catch (SQLException e) { if (e.getErrorCode() == 1062) { return 0; } e.printStackTrace(); ret = -2; } } return ret; }
public static void dbUpdate(Creative creative) throws Exception { Connection conn = null; PreparedStatement statement = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); conn = DriverManager.getConnection("database_url", "username", "password"); String query = "update creative set creativeID = ? , " + "creativeTimeStamp = ? " + "where creativeName = ?"; statement = (PreparedStatement) conn.prepareStatement(query); statement.setString(1, creative.getCreativeID()); statement.setString(2, creative.getCreativeTimestamp()); statement.setString(3, creative.getName()); statement.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { statement.close(); conn.close(); } }
public int insertSearchHistory(ApkBean apk) { int ret = -1; if (apk.marketBean.marketName == null || apk.searchKeyword == null || apk.searchResult == null || apk.searchResultNum < 0) return ret; String insertQuery = "INSERT INTO market_search_history(" + "market_name," + "search_keyword," + "update_time," + "result," + "result_num) " + "VALUES(?,?,NOW(),?,?); "; try { PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(insertQuery); pstmt.setString(1, apk.marketBean.marketName); pstmt.setString(2, apk.searchKeyword); pstmt.setString(3, apk.searchResult); pstmt.setInt(4, apk.searchResultNum); pstmt.execute(); ret = 0; } catch (SQLException e) { System.out.println( "You may have inserted duplicated search history in a short time. Please be patient."); e.printStackTrace(); ret = -2; } return ret; }
private void jbutLogActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jbutLogActionPerformed if (jtxtUser.getText().equals("")) { JOptionPane.showMessageDialog(this, "Enter Details"); return; } if (jtxtPass.getText().equals("")) { JOptionPane.showMessageDialog(this, "Enter Details"); return; } try { DBConnection bConnection = new DBConnection(); Connection con = bConnection.connect(); Statement stm = con.createStatement(); PreparedStatement s1 = (PreparedStatement) con.prepareStatement("Insert into login values(?,?,?)"); s1.setString(1, jtxtUser.getText()); s1.setString(2, jtxtPass.getText()); s1.setString(3, (String) jComboBox1.getSelectedItem()); int save = s1.executeUpdate(); JOptionPane.showMessageDialog(this, "Data Saved Successfully!!"); Clear(); } catch (Exception ee) { System.out.println(ee.getMessage()); JOptionPane.showMessageDialog(this, ee.getMessage()); } } // GEN-LAST:event_jbutLogActionPerformed
/** * Rate a restaurant and give a feedback Rate uses SQL INSERT INTO * * @param stars number of stars * @param feedback user's feedback * @param customer a customer * @return true if rate works fine, false otherwise * @throws SQLException */ public boolean rate(int stars, String feedback, Customer customer) throws SQLException { boolean success = false; PreparedStatement insertStatement = null; int customerID = getCID(customer.getEmail()); String query = "INSERT INTO Rating (cid, stars, feedback) VALUES (?,?,?) " + "ON DUPLICATE KEY UPDATE stars=?, feedback=?"; try { connection.setAutoCommit(false); insertStatement = (PreparedStatement) connection.prepareStatement(query); insertStatement.setInt(1, customerID); insertStatement.setInt(2, stars); insertStatement.setString(3, feedback); insertStatement.setInt(4, stars); insertStatement.setString(5, feedback); insertStatement.execute(); connection.commit(); success = true; } catch (SQLException e) { e.printStackTrace(); success = false; } finally { if (insertStatement != null) { insertStatement.close(); } connection.setAutoCommit(true); return success; } }
public static void createConnection(int card_n, String arr[]) { Connection conn = null; PreparedStatement stmt = null; try { // STEP 2: Register JDBC driver Class.forName("com.mysql.jdbc.Driver"); // STEP 3: Open a connection JOptionPane.showMessageDialog(null, "Connecting to a selected database..."); conn = (Connection) DriverManager.getConnection(DB_URL, USER, PASS); JOptionPane.showMessageDialog(null, "Connected database successfully..."); // STEP 4: Execute a query int flag = 0; try { String sql = "insert into registration (card_number,name,h_f_name,department,designation) values (?,?,?,?,?)"; stmt = (PreparedStatement) conn.prepareStatement(sql); stmt.setInt(1, card_n); stmt.setString(2, arr[0]); stmt.setString(3, arr[1]); stmt.setString(4, arr[2]); stmt.setString(5, arr[3]); stmt.execute(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Record not inerted. Duplicate entry!"); flag = 1; } // stmt.executeUpdate(sql); if (flag == 0) JOptionPane.showMessageDialog(null, "Inserted record in table!.."); } catch (SQLException se) { // Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { // Handle errors for Class.forName JOptionPane.showMessageDialog(null, "ERROR!"); e.printStackTrace(); } finally { // finally block used to close resources try { if (stmt != null) conn.close(); } catch (SQLException se) { } // do nothing try { if (conn != null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } // end finally try } // end try JOptionPane.showMessageDialog(null, "Goodbye!"); } // end main
public static void main(String[] args) { // TODO Auto-generated method stub try { // create our mysql database connection String myUrl = "jdbc:mysql://biomedinformatics.is.umbc.edu/Alzheimer?autoReconnect=true&useSSL=false"; Connection conn = DriverManager.getConnection(myUrl, "weijianqin", "weijianqin"); // our SQL SELECT query. // if you only need a few columns, specify them by name instead of using "*" String query = "select Name,Alternate_Names,Accession_Id from PharmGKB_diseases"; // create the java statement Statement st = conn.createStatement(); // execute the query, and get a java resultset ResultSet rs = st.executeQuery(query); PreparedStatement pst_user = (PreparedStatement) conn.prepareStatement( "INSERT INTO DiseaseSynonyms(Synonyms,Disease,Accession_Id) VALUES(?,?,?)"); // iterate through the java resultset while (rs.next()) { if (rs.getString(2).length() > 0) { String disease = rs.getString("Name"); String AN = term_split(rs.getString(2)); String AI = rs.getString(3); // System.out.print(disease); String[] AN_arr = AN.split("&"); // print the results for (String str : AN_arr) { // System.out.print(str); pst_user.setString(1, str); pst_user.setString(2, disease); pst_user.setString(3, AI); pst_user.execute(); } // System.out.print("\n"); } } st.close(); } catch (Exception e) { System.err.println("Got an exception! "); System.err.println(e.getMessage()); } }
public void updateDokter(Dokter d, String idDokter) throws SQLException { try { PreparedStatement ps = (PreparedStatement) connection.prepareStatement(updateDokter); ps.setString(1, d.getNmDokter()); ps.setString(2, d.getIdSpesialis()); ps.setString(3, idDokter); ps.executeUpdate(); ps.close(); // JOptionPane.showMessageDialog(null, "Data dokter berhasil diubah!"); } catch (SQLException se) { // JOptionPane.showMessageDialog(null, se.getMessage(),"Update Dokter // Gagal!",JOptionPane.ERROR_MESSAGE); } }
public void lockIds(String marketName, String[] ids, boolean isLocked) { try { PreparedStatement pstmt; pstmt = (PreparedStatement) conn.prepareStatement(LOCK_IDS_QUERY); for (String id : ids) { pstmt.setBoolean(1, isLocked); pstmt.setString(2, marketName); pstmt.setString(3, id); pstmt.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } }
/** * @param status * @throws SQLException 更新胆码表状态内容 */ private void updateDanMaStatus(Fast3SiMa fast3SiMa) throws SQLException { Connection conn = ConnectSrcDb.getSrcConnection(); String sql = "UPDATE " + App.simaTbName + " SET DROWN_ISSUE_NUMBER=?,DROWN_NUMBER=?,status = ?,DROWN_CYCLE=? where ID = ?"; // System.out.println(sql); PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql); pstmt.setString(1, fast3SiMa.getDrownIssueNumber()); pstmt.setString(2, fast3SiMa.getDrownNumber()); pstmt.setString(3, fast3SiMa.getStatus()); pstmt.setInt(4, fast3SiMa.getDrownCycle()); pstmt.setInt(5, fast3SiMa.getId()); pstmt.executeUpdate(); }
public boolean select(String email) { con = (Connection) DBConnector.getConnection(); try { String sql = "SELECT mail_address FROM user WHERE mail_address = ?"; ps = (PreparedStatement) con.prepareStatement(sql); ps.setString(1, email); ResultSet rs = ps.executeQuery(); if (rs.next()) { rs.getString(1); result = true; } } catch (SQLException e) { e.printStackTrace(); } finally { if (con != null) { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } } return result; }
/** * retrieve food items from database * * @param type beverage or food , or null for combination * @return menu - list of items */ public ArrayList<Item> getMenu(String type) { String sql = "SELECT itemName, price, description FROM Menu"; if (type != null) { sql += " WHERE type=?"; } try { PreparedStatement statement = (PreparedStatement) connection.prepareStatement(sql); if (type != null) { statement.setString(0, type); } ResultSet rs = statement.executeQuery(); ArrayList<Item> menu = new ArrayList<Item>(); // maybe food menu if there is beverage menu while (rs.next()) { String itemName = rs.getString("itemName"); double price = rs.getDouble("price"); String desc = rs.getString("description"); Item i = new Item(itemName, price, desc); menu.add(i); } rs.close(); statement.close(); return menu; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub response.setContentType("text/html"); PrintWriter out = response.getWriter(); String username = request.getParameter("contacts"); String username_check = ""; try { Connection conn = new Database().dbconnection(); PreparedStatement ps = (PreparedStatement) conn.prepareStatement("select username from Users where username= ?"); ps.setString(1, username); ResultSet rs = ps.executeQuery(); while (rs.next()) { username_check = rs.getString("username"); } conn.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (username_check.equals(username) && username != "" && username != null) { String sender = request.getParameter("username"); RequestDispatcher friendRequest = request.getRequestDispatcher( "/jsp/FriendRequestOut.jsp?sender=" + sender + "&reciver=" + username); friendRequest.forward(request, response); } else out.println("User is not registered"); }
/** * Inserts a new entry in the `session` table. * * @param id I * @param root * @return A unique key associated with the user * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException * @throws SQLException */ public static String insertSession(int id, boolean root) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { /* SESSION_HOUR_DURATIONS starting from now */ Timestamp expires = new Timestamp(System.currentTimeMillis() + SESSION_HOUR_DURATION * 60 * 60 * 1000); String key = generateKey(); String sql = "INSERT INTO `session` " + "(`key`, `user_id`, `expires`, `root`)" + " VALUE(?,?,?,?)"; Connection connection = DataBaseUtils.getMySQLConnection(); PreparedStatement ps = (PreparedStatement) connection.prepareStatement(sql); ps.setString(1, key); ps.setInt(2, id); ps.setTimestamp(3, expires); ps.setBoolean(4, root); ps.executeUpdate(); System.out.println("Session inserted for id : " + id); ps.close(); connection.close(); return key; }
/** * Checks if the databasePassword is the same as the provided password. * * @param login * @param password * @return true / false * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException * @throws SQLException */ public static boolean checkPassword(String login, String password) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { String sql = "SELECT password FROM users WHERE login = ? "; String serverPassword = ""; Boolean isValid = false; Connection connection = DataBaseUtils.getMySQLConnection(); PreparedStatement ps = (PreparedStatement) connection.prepareStatement(sql); ps.setString(1, login); ResultSet rs = ps.executeQuery(); if (rs.next()) { serverPassword = rs.getString("password"); if (password.equals(serverPassword)) { isValid = true; } } ps.close(); connection.close(); return isValid; }
/** * Add a customer * * @param ln last name * @param fn fist name * @param email email * @return true if succeed, false otherwise */ public boolean addCustomer(String ln, String fn, String email) { String sql_addcustomer = "INSERT INTO CUSTOMER (email,lastname,firstname) VALUES (?,?,?)"; try { PreparedStatement addCustomer = (PreparedStatement) connection.prepareStatement(sql_addcustomer); addCustomer.setString(1, email); addCustomer.setString(2, ln); addCustomer.setString(3, fn); addCustomer.execute(); addCustomer.close(); return true; } catch (SQLException e) { e.printStackTrace(); System.out.println(e.getMessage()); return false; } }
public void initIdLib(String marketName, String[] ids) { PreparedStatement pstmt; try { pstmt = (PreparedStatement) conn.prepareStatement(EMPTY_ID_LIB_QUERY); pstmt.setString(1, marketName); pstmt.execute(); pstmt = (PreparedStatement) conn.prepareStatement(INIT_ID_LIB_QUERY); for (String id : ids) { pstmt.setString(1, marketName); pstmt.setString(2, id); pstmt.executeUpdate(); } } catch (SQLException e) { e.printStackTrace(); } }
public void resetLocks(String marketName) { try { PreparedStatement pstmt; pstmt = (PreparedStatement) conn.prepareStatement(RESET_ID_LOCK_QUERY); pstmt.setString(1, marketName); pstmt.execute(); pstmt.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } }
public void deleteDokter(String idDokter) throws SQLException { try { PreparedStatement ps = (PreparedStatement) connection.prepareStatement(deleteDokter); ps.setString(1, idDokter); ps.executeUpdate(); ps.close(); // JOptionPane.showMessageDialog(null, "Data dokter berhasil dihapus!"); } catch (SQLException se) { // JOptionPane.showMessageDialog(null, se.getMessage(),"Delete Dokter // Gagal!",JOptionPane.ERROR_MESSAGE); } }
/** * Adds a new username to the data-base. * * @param login username * @param password password * @param email email * @return true / false * @throws SQLException * @throws ClassNotFoundException * @throws IllegalAccessException * @throws InstantiationException */ public static boolean addUserToDataBase(String login, String password, String email) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { String sql = "INSERT INTO users " + "(login, password, email)" + " VALUES (?, ?, ?)"; Boolean isAdded = false; Connection connection = DataBaseUtils.getMySQLConnection(); PreparedStatement ps = (PreparedStatement) connection.prepareStatement(sql); ps.setString(1, login); ps.setString(2, password); ps.setString(3, email); ps.executeUpdate(); isAdded = true; ps.close(); connection.close(); System.out.println("User Added To Database"); return isAdded; }
public boolean save(DamageItem d) throws Exception { String sql = "insert into damaged (item, qty, reason, date, staffStamp) values (?, ?, ?, ?, ?)"; try { con = db.getConnect(); PreparedStatement statement = (PreparedStatement) con.prepareStatement(sql); // statement.setInt(1, d.getId()); statement.setString(1, d.getItem()); statement.setInt(2, d.getQty()); statement.setString(3, d.getReason()); statement.setString(4, d.getDate()); statement.setString(5, d.getStaffstamp()); statement.execute(); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
public void setAlterar(ClassConecta conexao) { try { // ClassConecta conexao = new ClassConecta(); // conexao.conecta(); String comando = "UPDATE tipos_fornecedores " + " SET " + " TIPO_FORNECEDOR = ?, " + " GRUPO = ?, " + " OBS = ? " + " WHERE " + " COD_TIPO_FORNECEDOR = ?"; System.out.println("Executando operação..."); PreparedStatement stmt = (PreparedStatement) ClassConecta.con.prepareStatement(comando); stmt.setString(1, getTipo_fornecedor()); stmt.setString(2, getGrupo()); stmt.setString(3, getObs()); stmt.setInt(4, getCod_tipo_fornecedor()); stmt.executeUpdate(); System.out.println("Transação Concluída"); JOptionPane.showMessageDialog( null, "O REGISTRO foi salvo com sucesso.", "ATENÇÃO", JOptionPane.INFORMATION_MESSAGE); } catch (Exception e) { System.err.println("Erro na Transação\n" + e); JOptionPane.showMessageDialog( null, "Erro na Transação", "ATENÇÃO", JOptionPane.ERROR_MESSAGE); } }
// TODO public int insertApk(ApkBean apk) { int ret = -1; if (apk.marketBean.marketName == null || apk.packageName == null || apk.packageName == null || apk.marketBean.marketAppName == null || apk.versionCode == 0 || apk.versionName == null) return ret; // Update market database try { PreparedStatement pstmt = null; String marketUpdateQuery = "INSERT INTO market_" + apk.marketBean.marketName.trim().toLowerCase() + "(package_name," + "version_code," + "update_time," + "app_name," + "download_url," + "p_id)" + " VALUES( ?, ?, CURDATE(), ?, ?, ?) ON DUPLICATE KEY UPDATE check_times= check_times+1"; pstmt = (PreparedStatement) conn.prepareStatement(marketUpdateQuery); pstmt.setString(1, apk.packageName.trim()); pstmt.setInt(2, apk.versionCode); pstmt.setString(3, apk.marketBean.marketAppName.trim()); pstmt.setString(4, apk.marketBean.marketDownloadUrl.trim()); pstmt.setString(5, apk.marketBean.marketPid.trim()); pstmt.executeUpdate(); ret = 0; } catch (SQLException e) { e.printStackTrace(); ret = -2; } return ret; }
public void setCadastrar() { try { String comando = "INSERT INTO tipos_fornecedores " + " (COD_TIPO_FORNECEDOR, " + " TIPO_FORNECEDOR, " + " GRUPO, " + " OBS " + " ) " + " VALUES " + " (null, " + " ?, " + " ?, " + " ? " + " ); "; System.out.println("Executando operação..."); PreparedStatement stmt = (PreparedStatement) ClassConecta.con.prepareStatement(comando); stmt.setString(1, getTipo_fornecedor()); stmt.setString(2, getGrupo()); stmt.setString(3, getObs()); stmt.execute(); // System.out.println("Transação Concluída"); // JOptionPane.showMessageDialog(null, "Transação Concluída", "ATENÇÃO", // JOptionPane.WARNING_MESSAGE); } catch (Exception e) { System.err.println("Erro na Transação\n" + e); JOptionPane.showMessageDialog( null, "Erro na Transação", "ATENÇÃO", JOptionPane.ERROR_MESSAGE); } }
/** * Removes the entry associated with id, from the `sessions` table. * * @param id user id * @throws InstantiationException * @throws IllegalAccessException * @throws ClassNotFoundException * @throws SQLException */ public static void removeSession(String key) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException { String sql = "DELETE FROM session WHERE `key`=?"; Connection connection = DataBaseUtils.getMySQLConnection(); PreparedStatement ps = (PreparedStatement) connection.prepareStatement(sql); ps.setString(1, key); ps.executeUpdate(); System.out.println("Session removed for key : " + key); ps.close(); connection.close(); }
public String[] getIds(String marketName, int limitNum) { ArrayList<String> ids = new ArrayList<String>(); try { PreparedStatement pstmt; pstmt = (PreparedStatement) conn.prepareStatement(GET_IDS_QUERY); pstmt.setString(1, marketName); pstmt.setInt(2, limitNum); ResultSet rs = pstmt.executeQuery(); while (rs.next()) { ids.add(String.valueOf(rs.getInt("p_id"))); } } catch (SQLException e) { e.printStackTrace(); } return ids.toArray(new String[ids.size()]); }