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.reydentx.core.client.MySQLClient.java
public void close(java.sql.Statement st) { try {// w w w . java 2 s. com if (st != null && !st.isClosed()) { st.close(); } } catch (Exception ex) { _logger.error(ex.getMessage(), ex); } }
From source file:de.langmi.spring.batch.examples.readers.support.CompositeCursorItemReaderTest.java
/** * Create a table and fill with some test data. * * @param dataSource//from w ww. j av a2 s. c o m * @throws Exception */ private void createTableWithTestData(final DataSource dataSource) throws Exception { // create table Connection conn = dataSource.getConnection(); Statement st = conn.createStatement(); st.execute(CREATE_TEST_TABLE); conn.commit(); st.close(); conn.close(); // fill with values conn = dataSource.getConnection(); // prevent auto commit for batching conn.setAutoCommit(false); PreparedStatement ps = conn.prepareStatement(INSERT); // fill with values for (int i = 0; i < EXPECTED_COUNT; i++) { ps.setString(1, String.valueOf(i)); ps.addBatch(); } ps.executeBatch(); conn.commit(); ps.close(); conn.close(); }
From source file:com.adito.jdbc.JDBCConnectionImpl.java
void execute(String sqlString) throws SQLException { Statement stmt = conn.createStatement(); try {//from www . j a va 2 s .c om stmt.execute(sqlString); } finally { stmt.close(); } }
From source file:org.flywaydb.test.sample.spring3.BaseDBHelper.java
/** * Simple counter query to have simple test inside test methods. * * @return number of customer in database * @throws Exception// w w w .jav a 2 s . c o m */ public int countCustomer() throws Exception { int result = -1; Statement stmt = con.createStatement(); String query = "select count(*) from Customer"; ResultSet rs = stmt.executeQuery(query); rs.next(); Long cnt = rs.getLong(1); result = cnt.intValue(); rs.close(); stmt.close(); return result; }
From source file:com.alibaba.druid.benckmark.pool.Oracle_Case4.java
private void printAV_INFO(DataSource dataSource) throws SQLException { String sql = "SELECT DISTINCT ID FROM AV_INFO WHERE ROWNUM <= 10"; Connection conn = dataSource.getConnection(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(sql); JdbcUtils.printResultSet(rs);// ww w. j a v a 2s . com rs.close(); stmt.close(); conn.close(); }
From source file:org.flywaydb.test.sample.helper.BaseDBHelper.java
/** * Simple counter query to have simple test inside test methods. * /*from w w w . jav a2 s . c om*/ * @return number of customer in database * @throws Exception */ public int countCustomer() throws Exception { int result = -1; Statement stmt = con.createStatement(); String query = "select count(*) from Customer"; ResultSet rs = stmt.executeQuery(query); rs.next(); Long cnt = rs.getLong(1); result = cnt.intValue(); rs.close(); stmt.close(); return result; }
From source file:ems.util.DataHandler.java
public static List<MyModel> getWardList() { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = "select distinct ward_no from bmc_history order by 1"; Connection con = getConnection(); Statement s = null; ResultSet rs = null;/*from ww w.j av a2s.c om*/ try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); myModels.add(new MyModel("0", "Choose Ward No.")); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(1))); } } catch (Exception e) { log.error("getWardList: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getWardList: " + ex.getMessage()); } } return myModels; }
From source file:ems.util.DataHandler.java
public static List<MyModel> getCommunityList() { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = "select distinct cast_nm from e_details where cast_nm is not null and cast_nm <>'' order by 1"; Connection con = getConnection(); Statement s = null; ResultSet rs = null;/*from www.ja v a 2 s . co m*/ try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); myModels.add(new MyModel("0", "Choose Community")); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(1))); } } catch (Exception e) { log.error("getWardList: " + e.getMessage()); } finally { try { if (rs != null) { rs.close(); } if (s != null) { s.close(); } if (con != null) { con.close(); } } catch (SQLException ex) { log.error("getWardList: " + ex.getMessage()); } } return myModels; }
From source file:ems.util.DataHandler.java
public static List<MyModel> getBoothList() { List<MyModel> myModels = new LinkedList<>(); String sqlQuery = "select distinct booth_no, booth_id from booth_master order by 1"; Connection con = getConnection(); Statement s = null; ResultSet rs = null;// w w w . j a va 2 s . co m try { s = con.createStatement(); rs = s.executeQuery(sqlQuery); myModels.add(new MyModel("0", "Choose Booth No.")); while (rs.next()) { myModels.add(new MyModel(rs.getString(1), rs.getString(2))); } } 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 myModels; }