List of usage examples for java.sql PreparedStatement 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.xpfriend.fixture.runner.example.ExampleJob.java
/** * ??/*from ww w. j ava2s. c om*/ * @param id ?ID * @param name?NAME * @param connection ? */ private static void updateDatabase(int id, String name, Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement(SQL); try { statement.setString(1, name); statement.setInt(2, id); statement.executeUpdate(); } finally { statement.close(); } }
From source file:com.alibaba.druid.pool.bonecp.TestPSCache.java
public static void f(DataSource ds, int count) throws Exception { Connection conn = ds.getConnection(); for (int i = 0; i < count; ++i) { PreparedStatement stmt = conn.prepareStatement("SELECT 1"); System.out.println(System.identityHashCode(unwrap(stmt))); stmt.close(); }//from w ww.jav a2 s. c o m conn.close(); }
From source file:com.wso2telco.dep.subscriptionvalidator.util.ValidatorDBUtils.java
public static void closeStatement(PreparedStatement preparedStatement) { if (preparedStatement != null) { try {/*from w w w . jav a2s . c o m*/ preparedStatement.close(); } catch (SQLException var2) { log.warn("Database error. Could not close PreparedStatement. Continuing with others. - " + var2.getMessage(), var2); } } }
From source file:Main.java
public static Object readJavaObject(Connection conn, long id) throws Exception { PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL); pstmt.setLong(1, id);/*from w w w . ja v a 2 s . c o m*/ ResultSet rs = pstmt.executeQuery(); rs.next(); Object object = rs.getObject(1); String className = object.getClass().getName(); rs.close(); pstmt.close(); return object; }
From source file:SerializeJavaObjects_MySQL.java
public static Object readJavaObject(Connection conn, long id) throws Exception { PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL); pstmt.setLong(1, id);// w w w . ja v a2 s . c om ResultSet rs = pstmt.executeQuery(); rs.next(); Object object = rs.getObject(1); String className = object.getClass().getName(); rs.close(); pstmt.close(); System.out.println("readJavaObject: done de-serializing: " + className); return object; }
From source file:eu.earthobservatory.testsuite.utils.Utils.java
public static void dropdb() throws SQLException { strabon.close();/*from w ww .j a v a 2 s .co m*/ //Drop the temp database conn.close(); String url = "jdbc:postgresql://" + serverName + ":" + port; conn = DriverManager.getConnection(url, username, password); PreparedStatement pst = conn.prepareStatement("DROP DATABASE " + databaseName); pst.executeUpdate(); pst.close(); conn.close(); }
From source file:Main.java
public static Object readJavaObject(Connection conn, long id) throws Exception { PreparedStatement pstmt = conn.prepareStatement(READ_OBJECT_SQL); pstmt.setLong(1, id);//from w w w .j a v a 2 s.c o m ResultSet rs = pstmt.executeQuery(); rs.next(); Object object = rs.getObject("object_value"); String className = object.getClass().getName(); rs.close(); pstmt.close(); return object; }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the {@link PreparedStatement#addBatch() batches}, get the number of rows affected in * each batch, and close the statement./*w ww . j av a 2 s. c om*/ * * @param stmt * must already have batches added * @return null if the statement is null * @since 1.4.0 */ public static int[] batch(PreparedStatement stmt) throws SQLException { int[] rows = null; if (stmt != null) { rows = stmt.executeBatch(); stmt.close(); } return rows; }
From source file:com.nabla.wapp.server.database.Database.java
public static boolean executeUpdate(final Connection conn, final String sql, final Object... parameters) throws SQLException { final PreparedStatement stmt = StatementFormat.prepare(conn, sql, parameters); try {//from ww w . jav a 2s.c o m return stmt.executeUpdate() == 1; } finally { stmt.close(); } }
From source file:net.sf.sprockets.sql.Statements.java
/** * Execute the query, get the long value in the first row and column of the result set, and * close the statement.//w ww . j a v a 2 s . c o m * * @param stmt * must already have parameters set * @return {@link Long#MIN_VALUE} if the result set is empty */ public static long firstLong(PreparedStatement stmt) throws SQLException { ResultSet rs = stmt.executeQuery(); long l = rs.next() ? rs.getLong(1) : Long.MIN_VALUE; stmt.close(); return l; }