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:com.wso2.raspberrypi.Util.java
public static List<KVPair> getKeyValuePairs() { List<KVPair> results = new ArrayList<KVPair>(); BasicDataSource ds = getBasicDataSource(); Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null; try {/*from w ww. ja v a 2 s. c o m*/ dbConnection = ds.getConnection(); prepStmt = dbConnection.prepareStatement("SELECT * FROM KV_PAIR ORDER BY k"); rs = prepStmt.executeQuery(); while (rs.next()) { results.add(new KVPair(rs.getString("k"), rs.getString("v"))); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (dbConnection != null) { dbConnection.close(); } if (prepStmt != null) { prepStmt.close(); } if (rs != null) { rs.close(); } } catch (SQLException e) { e.printStackTrace(); } } return results; }
From source file:com.wso2.raspberrypi.Util.java
public static RaspberryPi getRaspberryPi(String macAddress) { System.out.println("Listing Raspberry Pi with Mac Address: " + macAddress); RaspberryPi pi = null;/*from w ww . j a va 2 s.c om*/ BasicDataSource ds = getBasicDataSource(); Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null; try { dbConnection = ds.getConnection(); prepStmt = dbConnection.prepareStatement("SELECT * FROM RASP_PI WHERE mac='" + macAddress + "'"); rs = prepStmt.executeQuery(); while (rs.next()) { pi = toRaspberryPi(rs); break; } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (dbConnection != null) { dbConnection.close(); } if (prepStmt != null) { prepStmt.close(); } if (rs != null) { rs.close(); } } catch (SQLException e) { e.printStackTrace(); } } return pi; }
From source file:com.l2jfree.gameserver.datatables.HennaTable.java
private void restoreHennaData() { Connection con = null;/*from w w w .j av a 2 s . co m*/ try { con = L2DatabaseFactory.getInstance().getConnection(con); PreparedStatement statement = con.prepareStatement(LOAD_HENNA); ResultSet hennadata = statement.executeQuery(); fillHennaTable(hennadata); hennadata.close(); statement.close(); } catch (Exception e) { _log.error("error while creating henna table!", e); } finally { L2DatabaseFactory.close(con); } }
From source file:com.wso2.raspberrypi.Util.java
public static List<RaspberryPi> getSelectedPis() { List<RaspberryPi> results = new ArrayList<RaspberryPi>(); BasicDataSource ds = getBasicDataSource(); Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null; try {//from w w w . j a va 2 s .c o m dbConnection = ds.getConnection(); prepStmt = dbConnection.prepareStatement("SELECT * FROM RASP_PI WHERE selected=true"); rs = prepStmt.executeQuery(); while (rs.next()) { RaspberryPi pi = toRaspberryPi(rs); results.add(pi); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (dbConnection != null) { dbConnection.close(); } if (prepStmt != null) { prepStmt.close(); } if (rs != null) { rs.close(); } } catch (SQLException e) { e.printStackTrace(); } } return results; }
From source file:jp.primecloud.auto.tool.management.db.DBConnector.java
public void closeConnection(Connection con, Statement stmt, ResultSet rs) throws SQLException { if (rs != null) { try {/* ww w . j a v a 2 s . co m*/ rs.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } if (stmt != null) { try { stmt.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } if (con != null) { try { con.close(); } catch (SQLException e) { log.error(e.getMessage(), e); } } }
From source file:it.unibas.spicy.persistence.relational.SimpleDbConnectionFactory.java
public void close(ResultSet resultSet) { try {// ww w . java2 s.c om if (resultSet != null) { resultSet.close(); } } catch (SQLException sqle) { logger.fatal(sqle.toString()); } }
From source file:com.wso2.raspberrypi.Util.java
public static List<RaspberryPi> getRaspberryPis(String orderBy) { System.out.println("Listing registered Raspberry Pis..."); if (orderBy == null) { orderBy = "ip"; }// ww w. j av a 2s.c om List<RaspberryPi> results = new ArrayList<RaspberryPi>(); BasicDataSource ds = getBasicDataSource(); Connection dbConnection = null; PreparedStatement prepStmt = null; ResultSet rs = null; try { dbConnection = ds.getConnection(); prepStmt = dbConnection.prepareStatement("SELECT * FROM RASP_PI ORDER BY " + orderBy); rs = prepStmt.executeQuery(); while (rs.next()) { RaspberryPi pi = toRaspberryPi(rs); results.add(pi); } } catch (SQLException e) { e.printStackTrace(); } finally { try { if (dbConnection != null) { dbConnection.close(); } if (prepStmt != null) { prepStmt.close(); } if (rs != null) { rs.close(); } } catch (SQLException e) { e.printStackTrace(); } } return results; }
From source file:com.espertech.esper.epl.db.TestDatabaseDMConnFactory.java
private void tryAndCloseConnection(Connection connection) throws Exception { Statement stmt = connection.createStatement(); stmt.execute("select 1 from dual"); ResultSet result = stmt.getResultSet(); result.next();//from w ww . jav a 2s. c o m assertEquals(1, result.getInt(1)); result.close(); stmt.close(); connection.close(); }
From source file:Performance.java
public void run() { long startTime; try {/* w w w. j a v a 2 s .c o m*/ /* * PreparedStatement ps = connection.prepareStatement("INSERT INTO * product VALUES(null, 'title', 5.54, 'supplier', null, ?)"); * startTime = new Date().getTime(); for (int i=0;i <1000;i++) { * ps.setInt(1, i); ps.executeUpdate(); } System.out.println("INSERT = " + * ((new Date().getTime()) - startTime)); */ Statement statement = connection.createStatement(); startTime = new Date().getTime(); for (int i = 0; i < 60; i++) { ResultSet rs = statement .executeQuery("SELECT pic_id, length, tlength, ts FROM them limit 100, " + (i * 1000)); rs.close(); } // ResultSet rs = statement.executeQuery("SELECT pic_id, length, // tlength, ts FROM them"); // rs.close(); statement.close(); System.out.println("SELECT = " + ((new Date().getTime()) - startTime)); /* * ps = connection.prepareStatement("UPDATE product SET inventory=10 * WHERE inventory = ?"); startTime = new Date().getTime(); for (int * i=0;i <1000;i++) { ps.setInt(1, i); ps.executeUpdate(); } * System.out.println("UPDATE = " + ((new Date().getTime()) - * startTime)); */ connection.close(); } catch (SQLException e) { } }
From source file:com.manning.junitbook.ch14.ejb.AdministratorBean.java
/** * This mehtod extracts information from the database and constructs a * java.util.Collection from the rows.//from w ww . j a v a 2 s.co m */ public Collection execute(String sql) throws Exception { Connection connection = getConnection(); ResultSet resultSet = connection.createStatement().executeQuery(sql); RowSetDynaClass rsdc = new RowSetDynaClass(resultSet); resultSet.close(); connection.close(); return rsdc.getRows(); }