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.kylinolap.rest.service.BasicService.java
protected static void close(ResultSet resultSet, Statement stat, Connection conn) { OLAPContext.clearParameter();/*w w w . j a v a 2s. c om*/ if (resultSet != null) try { resultSet.close(); } catch (SQLException e) { logger.error("failed to close", e); } if (stat != null) try { stat.close(); } catch (SQLException e) { logger.error("failed to close", e); } if (conn != null) try { conn.close(); } catch (SQLException e) { logger.error("failed to close", e); } }
From source file:com.autentia.tnt.bill.migration.BillToBillPaymentMigration.java
private static void liberaConexion(Connection con, Statement stmt, ResultSet rs) { if (rs != null) { try {/*from w w w . ja v a2 s. co m*/ rs.close(); } catch (SQLException sqlex) { log.error("Error al liberar el ResultSet", sqlex); } } if (stmt != null) { try { stmt.close(); } catch (SQLException sqlex) { log.error("Error al liberar el Statement", sqlex); } } if (con != null) { try { con.close(); } catch (SQLException sqlex) { log.error("Error al liberar la conexin", sqlex); } } }
From source file:eu.earthobservatory.testsuite.utils.Utils.java
public static void createdb() throws Exception { String url = ""; ArrayList<String> databases = new ArrayList<String>(); PreparedStatement pst = null; //Read properties Properties properties = new Properties(); InputStream propertiesStream = Utils.class.getResourceAsStream(dbPropertiesFile); properties.load(propertiesStream);/*from www . ja v a2 s. c om*/ if ((databaseTemplateName = System.getProperty("postgis.databaseTemplateName")) == null) { databaseTemplateName = properties.getProperty("postgis.databaseTemplateName"); } if ((serverName = System.getProperty("postgis.serverName")) == null) { serverName = properties.getProperty("postgis.serverName"); } if ((username = System.getProperty("postgis.username")) == null) { username = properties.getProperty("postgis.username"); } if ((password = System.getProperty("postgis.password")) == null) { password = properties.getProperty("postgis.password"); } if ((port = System.getProperty("postgis.port")) == null) { port = properties.getProperty("postgis.port"); } //Connect to server and create the temp database url = "jdbc:postgresql://" + serverName + ":" + port; conn = DriverManager.getConnection(url, username, password); pst = conn.prepareStatement("SELECT * FROM pg_catalog.pg_database"); ResultSet rs = pst.executeQuery(); while (rs.next()) { databases.add(rs.getString(1)); } rs.close(); pst.close(); databaseName = "teststrabon" + (int) (Math.random() * 10000); while (databases.contains(databaseName)) { databaseName += "0"; } pst = conn.prepareStatement("CREATE DATABASE " + databaseName + " TEMPLATE " + databaseTemplateName); pst.executeUpdate(); pst.close(); conn.close(); url = "jdbc:postgresql://" + serverName + ":" + port + "/" + databaseName; conn = DriverManager.getConnection(url, username, password); strabon = new Strabon(databaseName, username, password, Integer.parseInt(port), serverName, true); }
From source file:edu.mayo.cts2.uriresolver.dao.DAOUtiltities.java
public static boolean tableExists(DatabaseMetaData metaData, String tablename) { //ResultSet tables = metaData.getTables(null, "public", "%" ,new String[] {"TABLE"} ); ResultSet tables = null; try {//w w w . ja va 2s .c om tables = metaData.getTables(null, null, tablename, null); if (tables.next()) { tables.close(); return true; } } catch (SQLException e) { return false; } finally { if (tables != null) { try { tables.close(); } catch (SQLException e1) { logger.error("Error while colsing result set: " + e1.getMessage()); } } } return false; }
From source file:com.skilrock.lms.common.db.DBConnect.java
public static void closeRs(ResultSet rs) { try {// w w w . jav a 2 s. co m if (rs == null) logger.info("ResultSet Already Closed Or Empty"); else rs.close(); } catch (SQLException ex) { logger.error("Problem While closing ResultSet"); ex.printStackTrace(); } }
From source file:edumsg.core.PostgresConnection.java
public static void disconnect(ResultSet rs, PreparedStatement statment, Connection conn, Statement query) { if (rs != null) { try {//from w ww .j ava 2 s .c o m rs.close(); } catch (SQLException e) { } } if (statment != null) { try { statment.close(); } catch (SQLException e) { } } if (conn != null) { try { conn.close(); } catch (SQLException e) { } } if (query != null) { try { query.close(); } catch (SQLException e) { e.printStackTrace(); } } }
From source file:com.p6spy.engine.spy.P6TestUtil.java
public static int queryForInt(Connection con, String sql) throws SQLException { Statement stmt = null;//from w w w .j a va 2 s .co m ResultSet rs = null; try { stmt = con.createStatement(); rs = stmt.executeQuery(sql); rs.next(); return rs.getInt(1); } finally { if (rs != null) try { rs.close(); } catch (Exception e) { } if (stmt != null) try { stmt.close(); } catch (Exception e) { } } }
From source file:com.data2semantics.yasgui.server.db.ConnectionFactory.java
/** * Check if database exists/*from w ww .j a v a2 s . c o m*/ * @param connect * @param dbName * @return * @throws SQLException */ private static boolean databaseExists(Connection connect, String dbName) throws SQLException { Statement statement = connect.createStatement(); ResultSet resultSet = statement.executeQuery( "SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '" + dbName + "'"); boolean exists = resultSet.next(); statement.close(); resultSet.close(); return exists; }
From source file:com.nextep.designer.sqlgen.helpers.CaptureHelper.java
/** * Close the specified <code>ResultSet</code> and <code>Statement</code> objects if not * <code>null</code> while catching for potential {@link SQLException} that could be thrown by * the close operation if a database access error occurs. * // w w w.jav a 2 s .com * @param rset a {@link ResultSet} object to be closed; may be <code>null</code> * @param stmt a {@link Statement} object to be closed; may be <code>null</code> */ public static void safeClose(ResultSet rset, Statement stmt) { try { if (rset != null) rset.close(); } catch (SQLException sqle) { LOGGER.warn(SQLGenMessages.getString("captureHelper.closeResultSetFailed"), sqle); //$NON-NLS-1$ } try { if (stmt != null) stmt.close(); } catch (SQLException sqle) { LOGGER.warn(SQLGenMessages.getString("captureHelper.closeStatementFailed"), sqle); //$NON-NLS-1$ } }
From source file:net.hydromatic.optiq.impl.jdbc.JdbcSchema.java
private static void close(Connection connection, Statement statement, ResultSet resultSet) { if (resultSet != null) { try {/*from w w w . j av a 2 s . c o m*/ resultSet.close(); } catch (SQLException e) { // ignore } } if (statement != null) { try { statement.close(); } catch (SQLException e) { // ignore } } if (connection != null) { try { connection.close(); } catch (SQLException e) { // ignore } } }