List of usage examples for java.sql ResultSet isClosed
boolean isClosed() throws SQLException;
ResultSet
object has been closed. From source file:edu.umass.cs.reconfiguration.SQLReconfiguratorDB.java
private JSONObject getDemandStatsJSON(String name) { PreparedStatement pstmt = null; ResultSet recordRS = null; Connection conn = null;//from w w w .j a va2 s . com JSONObject demandStats = null; try { conn = this.getDefaultConn(); pstmt = this.getPreparedStatement(conn, getDemandTable(), name, Columns.DEMAND_PROFILE.toString()); recordRS = pstmt.executeQuery(); assert (!recordRS.isClosed()); while (recordRS.next()) { String msg = recordRS.getString(1); demandStats = new JSONObject(msg); } } catch (SQLException | JSONException e) { log.severe((e instanceof SQLException ? "SQL" : "JSON") + "Exception while getting slot for " + name + ":"); e.printStackTrace(); } finally { cleanup(pstmt, recordRS); cleanup(conn); } return demandStats; }
From source file:edu.umass.cs.reconfiguration.SQLReconfiguratorDB.java
private ReconfigurationRecord<NodeIDType> getReconfigurationRecordDB(String name) { long t0 = System.currentTimeMillis(); PreparedStatement pstmt = null; ResultSet recordRS = null; Connection conn = null;/*from ww w .j a v a 2s . c om*/ ReconfigurationRecord<NodeIDType> rcRecord = null; try { conn = this.getDefaultConn(); pstmt = this.getPreparedStatement(conn, getRCRecordTable(), name, Columns.STRINGIFIED_RECORD.toString()); recordRS = pstmt.executeQuery(); assert (!recordRS.isClosed()); while (recordRS.next()) { String msg = recordRS.getString(1); rcRecord = new ReconfigurationRecord<NodeIDType>(new JSONObject(msg), this.consistentNodeConfig); } } catch (SQLException | JSONException e) { log.severe((e instanceof SQLException ? "SQL" : "JSON") + "Exception while getting RC record for " + name + ":"); e.printStackTrace(); } finally { cleanup(pstmt, recordRS); cleanup(conn); } DelayProfiler.updateDelay("getrcrecord", t0); return rcRecord; }
From source file:fetchBookDetails.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request//w w w. j av a 2s . co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //processRequest(request, response); try { System.out.println("Inside try 1"); Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); //setting up connection String dbURL = "jdbc:derby://localhost:1527/autolib_db_test"; Connection conn = DriverManager.getConnection(dbURL, "ishtiaq", "ishtiaq"); Statement stmt = null; ResultSet rslt = null; if (conn == null) { System.out.println("Connection Failed"); } stmt = conn.createStatement(); String bookId = request.getParameter("book"); // pass this book value from displayBookDetails function String buyBook = request.getParameter("buy"); // pass this book value from displayBookDetails function String sqlQry = ""; if (buyBook.equals("YES")) { //if a book is selected to be bought Integer bookQty = Integer.parseInt(request.getParameter("qty")); // pass this book value from displayBookDetails function sqlQry = "update books_tbl set qty = qty - " + bookQty.toString() + " where id = " + bookId + ""; //reducing quantity by bookQty which increments by 1 on every click stmt.execute(sqlQry); //executing the update query } System.out.println("SEARCH Book id " + bookId); //query to return book details by giving the ID value sqlQry = "SELECT * FROM books_tbl where id = " + bookId + ""; rslt = stmt.executeQuery(sqlQry); //creating JSON object, array object and a jason variable JSONObject jObj = new JSONObject(); JSONArray bookArr = new JSONArray(); JSONObject bookData; try { System.out.println("Inside Try"); //adding ID, name, author, price, topic, available and qty to bookData by using put while (rslt.next()) { bookData = new JSONObject(); bookData.put("id", rslt.getInt("id")); bookData.put("name", rslt.getString("bookname")); bookData.put("author", rslt.getString("author")); bookData.put("price", rslt.getInt("price")); bookData.put("topic", rslt.getString("topic")); bookData.put("available", rslt.getBoolean("available")); bookData.put("qty", rslt.getInt("qty")); bookArr.put(bookData); //putting all bookdata in book array } jObj.put("Books", bookArr); //adding book array content to string named "Books" } catch (JSONException jse) { } response.setContentType("application/json"); response.getWriter().write(jObj.toString()); //closing connection if (!stmt.isClosed()) stmt.close(); if (!rslt.isClosed()) rslt.close(); } catch (Exception e) { //return null; } }
From source file:com.smict.person.data.DoctorData.java
public boolean DoctorTreatmentMoreCheck(DoctorModel doc) { String SQL = "SELECT doctor_id,treatment_id,can_change_from_scope " + "FROM doctor_treatment " + "WHERE doctor_id = " + doc.getDoctorID() + " and treatment_id = '" + doc.getTreatment_Code() + "'"; boolean newAllergic = true; try {//from w w w . ja v a 2 s .co m conn = agent.getConnectMYSql(); Stmt = conn.createStatement(); ResultSet rs = Stmt.executeQuery(SQL); while (rs.next()) { newAllergic = false; } if (!rs.isClosed()) rs.close(); if (!Stmt.isClosed()) Stmt.close(); if (!conn.isClosed()) conn.close(); return newAllergic; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return newAllergic; }
From source file:com.smict.person.data.DoctorData.java
public boolean CheckDoctorPricelistDefault(String cateID, int docID) { String SQL = "SELECT * " + "FROM doctor_pricelist_default_rel_categories " + "WHERE doctor_pricelist_default_rel_categories.category_id ='" + cateID + "' " + "AND doctor_pricelist_default_rel_categories.doctor_id = '" + docID + "' "; boolean newAllergic = true; try {/*w w w .j av a 2 s. c o m*/ conn = agent.getConnectMYSql(); Stmt = conn.createStatement(); ResultSet rs = Stmt.executeQuery(SQL); while (rs.next()) { newAllergic = false; } if (!rs.isClosed()) rs.close(); if (!Stmt.isClosed()) Stmt.close(); if (!conn.isClosed()) conn.close(); return newAllergic; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return newAllergic; }
From source file:com.smict.person.data.DoctorData.java
public boolean branchStandardCheck(DoctorModel doc) { String SQL = "SELECT branch_standard_rel_doctor.price,branch.branch_name,doctor.first_name_th, " + "doctor.last_name_th,pre_name.pre_name_th, branch_standard_rel_doctor.branch_id " + "FROM branch " + "INNER JOIN branch_standard_rel_doctor ON branch.branch_id = branch_standard_rel_doctor.branch_id " + "INNER JOIN doctor ON doctor.doctor_id = branch_standard_rel_doctor.doctor_id " + "INNER JOIN pre_name ON doctor.pre_name_id = pre_name.pre_name_id " + "WHERE branch_standard_rel_doctor.doctor_id = " + doc.getDoctorID() + " and branch_standard_rel_doctor.branch_id = '" + doc.getBranch_id() + "'"; boolean newAllergic = true; try {/* www . j a v a 2 s . co m*/ conn = agent.getConnectMYSql(); Stmt = conn.createStatement(); ResultSet rs = Stmt.executeQuery(SQL); while (rs.next()) { newAllergic = false; } if (!rs.isClosed()) rs.close(); if (!Stmt.isClosed()) Stmt.close(); if (!conn.isClosed()) conn.close(); return newAllergic; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return newAllergic; }
From source file:com.smict.person.data.DoctorData.java
public boolean branchMgrCheck(DoctorModel doc) { String SQL = "SELECT branch_mgr_rel_doctor.price,branch.branch_name,doctor.first_name_th, " + "doctor.last_name_th,pre_name.pre_name_th, branch_mgr_rel_doctor.branch_id " + "FROM branch " + "INNER JOIN branch_mgr_rel_doctor ON branch.branch_id = branch_mgr_rel_doctor.branch_id " + "INNER JOIN doctor ON doctor.doctor_id = branch_mgr_rel_doctor.doctor_id " + "INNER JOIN pre_name ON doctor.pre_name_id = pre_name.pre_name_id " + "WHERE branch_mgr_rel_doctor.doctor_id = " + doc.getDoctorID() + " and branch_mgr_rel_doctor.branch_id = '" + doc.getBranch_id() + "'"; boolean newAllergic = true; try {/*from www.j a v a2s.c o m*/ conn = agent.getConnectMYSql(); Stmt = conn.createStatement(); ResultSet res = Stmt.executeQuery(SQL); while (res.next()) { newAllergic = false; } if (!res.isClosed()) res.close(); if (!Stmt.isClosed()) Stmt.close(); if (!conn.isClosed()) conn.close(); return newAllergic; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return newAllergic; }
From source file:org.apache.hadoop.hive.metastore.txn.TxnHandler.java
/** * Close the ResultSet.//from w w w . j av a 2 s . c om * @param rs may be {@code null} */ static void close(ResultSet rs) { try { if (rs != null && !rs.isClosed()) { rs.close(); } } catch (SQLException ex) { LOG.warn("Failed to close statement " + getMessage(ex)); } }
From source file:com.smict.person.data.DoctorData.java
public Map<String, String> GetDentistTreatment() throws IOException, Exception { String SQL = "SELECT id, nameth " + "FROM treatment_master "; conn = agent.getConnectMYSql();/* www . j a va2s . c o m*/ Stmt = conn.createStatement(); ResultSet rs = Stmt.executeQuery(SQL); Map<String, String> ResultList = new HashMap<String, String>(); while (rs.next()) { // vender_id,vender_name,create_by,create_datetime,update_by,update_datetime ResultList.put(rs.getString("id"), rs.getString("nameth")); } if (!rs.isClosed()) rs.close(); if (!Stmt.isClosed()) Stmt.close(); if (!conn.isClosed()) conn.close(); return ResultList; }
From source file:com.smict.person.data.DoctorData.java
public Map<String, String> GetSocpeTreatment() throws IOException, Exception { String SQL = "SELECT position_id, position_name_th " + "FROM doctor_position "; conn = agent.getConnectMYSql();//from w w w . j a va 2 s . c om Stmt = conn.createStatement(); ResultSet rs = Stmt.executeQuery(SQL); Map<String, String> ResultList = new HashMap<String, String>(); while (rs.next()) { // vender_id,vender_name,create_by,create_datetime,update_by,update_datetime ResultList.put(rs.getString("position_id"), rs.getString("position_name_th")); } if (!rs.isClosed()) rs.close(); if (!Stmt.isClosed()) Stmt.close(); if (!conn.isClosed()) conn.close(); return ResultList; }