List of usage examples for java.sql Statement close
void close() throws SQLException;
Statement
object's database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed. From source file:com.srotya.tau.wraith.silo.sql.TestSQLRulesStore.java
/** * Execute an SQL Query on a connection/* ww w . ja va2s.co m*/ * * @param connectionString * @param createTable * @throws SQLException */ public void runSQL(String connectionString, String createTable) throws SQLException { Connection conn = DriverManager.getConnection(connectionString); Statement st = conn.createStatement(); System.err.println(createTable); st.execute(createTable); st.close(); conn.close(); }
From source file:com.honnix.yaacs.core.data.processing.info.ACDBInfoHandler.java
private void closeStatement(Statement statement) { try {//from w ww . ja v a 2s .co m statement.close(); } catch (SQLException e) { LOG.warn(ERROR_CLOSING_STATEMENT, e); } }
From source file:gr.abiss.calipso.config.DataSourceFactoryBean.java
public void destroy() throws Exception { if (dataSource instanceof SingleConnectionDataSource) { logger.info("attempting to shut down embedded HSQLDB database"); Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); stmt.executeUpdate("SHUTDOWN"); stmt.close(); con.close();//from ww w .ja v a 2 s .c o m logger.info("embedded HSQLDB database shut down successfully"); } else if (dataSource instanceof BasicDataSource) { logger.info("attempting to close Apache DBCP data source"); ((BasicDataSource) dataSource).close(); logger.info("Apache DBCP data source closed successfully"); } else { logger.info("context shutting down for JNDI datasource"); } }
From source file:com.ibm.research.rdf.store.runtime.service.sql.StoreHelper.java
protected static void ensureExistenceOfUserTablespaceAndBuiltInRecursiveStoreProcedure(Connection con, Store store) throws RdfStoreException { if (!(store.getStoreBackend() == Backend.db2)) { // TODO for postgres return;//from ww w. j a v a2 s .c o m } TemporaryTableSpaceCreation cmd = new TemporaryTableSpaceCreation(USERTEMPTABLESPACE_NAME, USERTEMPTABLESPACE_FILE); Statement st = null; try { try { st = con.createStatement(); st.execute(cmd.toSQL()); store.setUserTablespace(USERTEMPTABLESPACE_NAME); st.execute(REACHABLENODES_PROC_DEF); } catch (SQLException ex) { } } finally { if (st != null) { try { st.close(); } catch (SQLException ex) { } } } }
From source file:TerminalMonitor.java
static public void executeStatement(StringBuffer buff) throws SQLException { String sql = buff.toString(); Statement statement = null; try {//from w w w .j av a 2s . c om statement = connection.createStatement(); if (statement.execute(sql)) { // true means the SQL was a SELECT processResults(statement.getResultSet()); } else { // no result sets, see how many rows were affected int num; switch (num = statement.getUpdateCount()) { case 0: System.out.println("No rows affected."); break; case 1: System.out.println(num + " row affected."); break; default: System.out.println(num + " rows affected."); } } } catch (SQLException e) { throw e; } finally { // close out the statement if (statement != null) { try { statement.close(); } catch (SQLException e) { } } } }
From source file:io.spring.batch.jsr.listener.DatabaseIntializer.java
@Override public void beforeJob() throws Exception { InputStream resourceAsStream = this.getClass().getResourceAsStream(scriptPath); BufferedReader reader = new BufferedReader(new InputStreamReader(resourceAsStream)); Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); String sql = reader.readLine(); while (sql != null) { stmt.execute(sql);// ww w. j av a2 s . c o m sql = reader.readLine(); } stmt.close(); con.close(); }
From source file:JDBCUtil.java
/** * Closes database statement and logs if an error * is encountered//w w w . j a va2 s .c o m * * @param stmt the statement to be closed */ public void closeJDBCStatement(Statement stmt) { try { if (stmt != null) { stmt.close(); } } catch (SQLException sqle) { // Log exception and continue subclassLogWrapper("Unexpected exception while closing database statement."); } }
From source file:com.evolveum.midpoint.tools.ninja.ImportDDL.java
private void readScript(File script, BufferedReader reader, Connection connection) throws IOException { System.out.println("Reading DDL script file '" + script.getAbsolutePath() + "'."); reader = new BufferedReader(new InputStreamReader(new FileInputStream(script), "utf-8")); StringBuilder query = new StringBuilder(); String line;//from w ww . ja v a2 s.co m while ((line = reader.readLine()) != null) { //skip comments if (line.length() == 0 || line.length() > 0 && line.charAt(0) == '-') { continue; } if (query.length() != 0) { query.append(' '); } query.append(line.trim()); //If one command complete if (query.charAt(query.length() - 1) == ';') { query.deleteCharAt(query.length() - 1); try { String queryStr = query.toString(); System.out.println("Executing query: " + queryStr); Statement stmt = connection.createStatement(); stmt.execute(queryStr); stmt.close(); } catch (SQLException ex) { System.out.println("Exception occurred during SQL statement '" + query.toString() + "' execute, reason: " + ex.getMessage()); } query = new StringBuilder(); } } }
From source file:ems.util.DataHandler.java
public static String getBoothName(String boothNumber) { String sqlQuery = "select ifnull(booth_no,'') || ' - ' || ifnull(booth_name,'') " + "from booth_master where booth_no=" + boothNumber; Connection con = getConnection(); Statement s = null; ResultSet rs = null;//ww w .ja va2 s . com try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); while (rs.next()) { return rs.getString(1); } } catch (Exception e) { log.error("getBoothList: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getBoothList: " + ex.getMessage()); } } return null; }
From source file:cc.osint.graphd.db.SQLDB.java
public JSONObject query(String expression) throws Exception { log.info("query(" + expression + ")"); Statement st = null; ResultSet rs = null;//from w ww . jav a 2s.com st = conn.createStatement(); rs = st.executeQuery(expression); JSONObject result = jsonizeResultSet(rs); st.close(); return result; }