List of usage examples for java.sql ResultSet close
void close() throws SQLException;
ResultSet
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:TestAppletPolicy.java
public void paint(Graphics g) { System.out.println("paint(): querying the database"); try {/*from w ww . j a v a 2 s. co m*/ Statement stmt = conn.createStatement(); ResultSet rset = stmt.executeQuery("select 'Hello '||initcap(USER) result from dual"); while (rset.next()) g.drawString(rset.getString(1), 10, 10); rset.close(); stmt.close(); } catch (SQLException e) { System.err.println("paint(): SQLException: " + e.getMessage()); } }
From source file:DbManager.java
/** * Close the ResultSet// ww w . j a v a 2 s .co m * * @param rst * the ResultSet */ public void close(ResultSet rst) { try { rst.close(); closeSingle(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.envirocar.aggregation.AggregatedTracksServlet.java
private String createTrackExists(String trackId) throws SQLException { ResultSet rs = this.connection.executeQueryStatement(String.format(trackQuery, trackId)); ObjectNode result = om.createObjectNode(); result.put("aggregated", rs.next()); rs.close(); return result.toString(); }
From source file:de.ingrid.importer.udk.strategy.v30.IDCStrategy3_0_0_fixFreeEntry.java
/** Read value of syslist entry from database ! * @param listId id of syslist//w ww . j a v a 2 s .c o m * @param entryId id of antry * @param language language of entry * @return returns null if not found * @throws Exception */ protected String readSyslistValue(int listId, int entryId, String language) throws Exception { String retValue = null; sqlStr = "SELECT name FROM sys_list WHERE lst_id = ? and entry_id = ? and lang_id = ?"; PreparedStatement ps = jdbc.prepareStatement(sqlStr); ps.setInt(1, listId); ps.setInt(2, entryId); ps.setString(3, language); ResultSet rs = ps.executeQuery(); while (rs.next()) { retValue = rs.getString("name"); } rs.close(); ps.close(); return retValue; }
From source file:edu.ku.brc.specify.conversion.ConvertMiscData.java
/** * @param oldDBConn//w ww .j ava 2 s . c om * @param newDBConn * @param disciplineID */ public static void convertMethodFromStratGTP(final Connection oldDBConn, final Connection newDBConn) { String sql = null; Session localSession = null; try { localSession = HibernateUtil.getCurrentSession(); HibernateUtil.beginTransaction(); // Query to Create PickList sql = "SELECT gtp.Name, CONCAT(gtp.Name,' - ', gtp.Standard) as Method FROM collectingevent AS ce " + "Inner Join stratigraphy AS s ON ce.CollectingEventID = s.StratigraphyID " + "Inner Join geologictimeperiod AS gtp ON s.GeologicTimePeriodID = gtp.GeologicTimePeriodID " + "GROUP BY gtp.Name"; PickList pl = (PickList) localSession.createQuery("FROM PickList WHERE Name = 'CollectingMethod'") .list().get(0); if (pl == null) { log.error("Couldn't find CollectingMethod."); } for (PickListItem pli : new Vector<PickListItem>(pl.getPickListItems())) { log.debug("Removing[" + pli.getTitle() + "]"); localSession.delete(pli); pl.getPickListItems().remove(pli); } localSession.saveOrUpdate(pl); HibernateUtil.commitTransaction(); HibernateUtil.beginTransaction(); Vector<Object[]> list = BasicSQLUtils.query(oldDBConn, sql); for (Object[] cols : list) { PickListItem pli = new PickListItem(); pli.initialize(); pli.setTitle(cols[1].toString()); pli.setValue(cols[0].toString()); pl.getPickListItems().add(pli); pli.setPickList(pl); localSession.saveOrUpdate(pli); } localSession.saveOrUpdate(pl); HibernateUtil.commitTransaction(); // Query for processing data sql = "SELECT ce.CollectingEventID, gtp.Name FROM collectingevent AS ce " + "Inner Join stratigraphy AS s ON ce.CollectingEventID = s.StratigraphyID " + "Inner Join geologictimeperiod AS gtp ON s.GeologicTimePeriodID = gtp.GeologicTimePeriodID " + "ORDER BY ce.CollectingEventID ASC"; IdMapperMgr.getInstance().setDBs(oldDBConn, newDBConn); IdMapperIFace mapper = IdMapperMgr.getInstance().addTableMapper("collectingevent", "CollectingEventID", false); PreparedStatement pStmt = newDBConn .prepareStatement("UPDATE collectingevent SET Method=? WHERE CollectingEventID=?"); Statement stmt = oldDBConn.createStatement(); ResultSet rs = stmt.executeQuery(sql); while (rs.next()) { Integer newId = mapper.get(rs.getInt(1)); pStmt.setString(1, rs.getString(2)); pStmt.setInt(2, newId); pStmt.executeUpdate(); } rs.close(); stmt.close(); } catch (Exception ex) { ex.printStackTrace(); HibernateUtil.rollbackTransaction(); } }
From source file:at.ac.tuwien.dsg.depic.external.algorithm.MySqlDataAssetStore.java
public int getNumberOfPartitionsByDataAssetID(String dataAssetID) { String sql = "Select COUNT(dataPartitionID) as counter FROM DataAsset WHERE dataAssetID='" + dataAssetID + "'"; ResultSet rs = connectionManager.ExecuteQuery(sql); int counter = 0; try {// www.jav a 2 s . co m while (rs.next()) { counter = rs.getInt("counter"); } rs.close(); } catch (SQLException ex) { Logger.getLogger(MySqlDataAssetStore.class.getName()).log(Level.SEVERE, null, ex); } return counter; }
From source file:net.mms_projects.copy_it.api.http.pages.v1.ClipboardGet.java
public FullHttpResponse onGetRequest(HttpRequest request, Database database, HeaderVerifier headerVerifier) throws Exception { if (!headerVerifier.getConsumerScope().canRead() || !headerVerifier.getUserScope().canRead()) throw new ErrorException(NO_READ_PERMISSION); PreparedStatement statement = database.getConnection().prepareStatement(SELECT_CONTENT); statement.setInt(1, headerVerifier.getUserId()); ResultSet result = statement.executeQuery(); if (result.first()) { final JSONObject json = new JSONObject(); json.put(CONTENT, result.getString(DATA)); json.put(LAST_UPDATED, result.getInt(LAST_UPDATED)); result.close(); return new DefaultFullHttpResponse(request.getProtocolVersion(), OK, Unpooled.copiedBuffer(json.toString(), CharsetUtil.UTF_8)); }//from ww w . j a v a2 s. c o m result.close(); throw new NoContentException(); }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java
protected void printTables(DruidDataSource dataSource) throws SQLException { Connection conn = dataSource.getConnection(); ResultSet rs = conn.getMetaData().getTables(null, "ALIBABA", null, new String[] { "TABLE" }); JdbcUtils.printResultSet(rs);/*ww w. j a va 2s .c om*/ rs.close(); conn.close(); }
From source file:ke.co.tawi.babblesms.server.persistence.contacts.PhoneDAO.java
/** * @see ke.co.tawi.babblesms.server.persistence.contacts.BabblePhoneDAO#getPhones(ke.co.tawi.babblesms.server.beans.contact.Contact) */// ww w .j ava 2 s . c o m @Override public List<Phone> getPhones(Contact contact) { List<Phone> phoneList = new ArrayList<>(); try (Connection conn = dbCredentials.getConnection(); PreparedStatement pstmt = conn.prepareStatement( "SELECT * FROM phone WHERE contactuuid = ? AND statusuuid='396F2C7F-961C-5C12-3ABF-867E7FD029E6';");) { pstmt.setString(1, contact.getUuid()); ResultSet rset = pstmt.executeQuery(); phoneList = beanProcessor.toBeanList(rset, Phone.class); rset.close(); } catch (SQLException e) { logger.error("SQL Exception when getting phones that belong to: " + contact); logger.error(ExceptionUtils.getStackTrace(e)); } return phoneList; }
From source file:com.imagelake.android.purchasemanagement.Servlet_purchaseVisePackages.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out = response.getWriter(); try {//from ww w . j a v a2 s .co m String type = request.getParameter("type"); String sql = "SELECT SQL_CALC_FOUND_ROWS user_has_packages.purchase_date,user_has_packages.expire_date,user_has_packages.user_id,user_has_packages.state,admin_package_income.total" + " FROM user_has_packages,admin_package_income WHERE user_has_packages.uhp_id=admin_package_income.uhp_id "; if (type != null && !type.equals("")) { if (type.equals("all")) { sql += "ORDER BY user_has_packages.purchase_date DESC "; ja = new JSONArray(); System.out.println("sql=" + sql); PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); if (rs.next()) { rs.close(); rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); DecimalFormat df = new DecimalFormat(); jo.put("pur_date", rs.getString(1)); jo.put("exp_date", rs.getString(2)); jo.put("un", udi.getUn(rs.getInt(3))); if (rs.getInt(4) == 1) { jo.put("state", 1); } else if (rs.getInt(4) == 2) { jo.put("state", 2); } jo.put("income", df.format(rs.getDouble(5))); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } else if (type.equals("sort")) { ja = new JSONArray(); String from = request.getParameter("date"); String to = request.getParameter("date2"); String cat = request.getParameter("cat"); String buy = request.getParameter("buy"); System.out.println("date_pur:" + from); System.out.println("date_exp:" + to); System.out.println("cat:" + cat); System.out.println("buy:" + buy); if (cat.equals("0")) { cat = ""; } if (from != null && !from.trim().equals("") && to != null && !to.trim().equals("")) { String[] dt = from.split("-"); String[] dt2 = to.split("-"); String orDate = dt[2] + "-" + dt[1] + "-" + dt[0]; String orDate2 = dt2[2] + "-" + dt2[1] + "-" + dt2[0]; System.out.println("date=" + orDate); sql += " AND user_has_packages.purchase_date BETWEEN '" + orDate + "' AND '" + orDate2 + "' "; } if (cat != null && !cat.trim().equals("")) { sql += " AND user_has_packages.package_type='" + cat + "' "; } if (buy != null && !buy.trim().equals("")) { sql += " AND user_has_packages.user_id='" + buy + "' "; } sql += "ORDER BY user_has_packages.purchase_date DESC "; System.out.println("sql: " + sql); PreparedStatement ps = DBFactory.getConnection().prepareStatement(sql); ResultSet rs = ps.executeQuery(); DecimalFormat df = new DecimalFormat(); if (rs.next()) { rs.close(); rs = ps.executeQuery(); while (rs.next()) { JSONObject jo = new JSONObject(); jo.put("pur_date", rs.getString(1)); jo.put("exp_date", rs.getString(2)); jo.put("un", udi.getUn(rs.getInt(3))); if (rs.getInt(4) == 1) { jo.put("state", 1); } else if (rs.getInt(4) == 2) { jo.put("state", 2); } jo.put("income", df.format(rs.getDouble(5))); ja.add(jo); } System.out.println(ja.toJSONString()); out.write("json=" + ja.toJSONString()); } else { out.write("msg=No item found."); } } } else { out.write("msg=Internal server error,Please try again later."); } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }