/** * Returns a connection from any datasource, with auto-commit enabled. */ public static Connection getConnection(String database) { return getConnection(database, true); }
/** * Returns a connection from the default datasource, with auto-commit enabled. */ public static Connection getConnection() { return getConnection("default"); }
/** * Returns a connection from the default datasource, * with auto-commit enabled. */ public static Connection getConnection() { return getConnection("default"); }
/** * Returns a connection from the default datasource, * with the specified auto-commit setting. */ public static Connection getConnection(boolean autocommit) { return getConnection("default", autocommit); }
/** * Returns a connection from any datasource, with auto-commit enabled. * * @param name Datasource name */ public static Connection getConnection(String name) { return getConnection(name, true); }
/** * Returns a connection from the default datasource, with the specified auto-commit setting. */ public static Connection getConnection(boolean autocommit) { return getConnection("default", autocommit); }
public static Connection getConnection() { return getConnection(DEFAULT); }
public static ResultSet execute(String sql, Object ... params) throws SQLException { PreparedStatement pst = DB.getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); int index = 0; for (Object param : params) { pst.setObject(++index, param); } return pst.executeQuery(); }
public static ResultSet executeList(String sql, List<Object> params) throws SQLException { PreparedStatement pst = DB.getConnection().prepareStatement(sql, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); int index = 0; for (Object param : params) { pst.setObject(++index, param); } return pst.executeQuery(); }
/** * Execute an SQL update * * @param name * the DB name * @param SQL * the SQL statement * @return true if the next result is a ResultSet object; false if it is an update count or there are no more * results */ public static boolean execute(String name, String SQL) { Statement statement = null; try { statement = getConnection(name).createStatement(); if (statement != null) { return statement.execute(SQL); } } catch (SQLException ex) { throw new DatabaseException(ex.getMessage(), ex); } finally { safeCloseStatement(statement); } return false; }
DB.getConnection(JPA.DEFAULT).setAutoCommit(false); } catch(Exception e) { Logger.error(e, "Why the driver complains here?");
/** * Flush the entire JDBC database */ public static void deleteDatabase() { try { idCache.clear(); List<String> names = new ArrayList<>(); ResultSet rs = DB.getConnection().getMetaData().getTables(null, null, null, new String[] { "TABLE" }); while (rs.next()) { String name = rs.getString("TABLE_NAME"); names.add(name); } disableForeignKeyConstraints(); for (String name : names) { if (Arrays.binarySearch(dontDeleteTheseTables, name) < 0) { if (Logger.isTraceEnabled()) { Logger.trace("Dropping content of table %s", name); } DB.execute(getDeleteTableStmt(name) + ";"); } } enableForeignKeyConstraints(); Play.pluginCollection.afterFixtureLoad(); } catch (Exception e) { throw new RuntimeException("Cannot delete all table data : " + e.getMessage(), e); } }
Statement exec = null; try { connect = DB.getConnection();
try { List<String> names = new ArrayList<>(); Connection connection = DB.getConnection();
DB.getConnection(name).setAutoCommit(false); } catch (Exception e) { Logger.error(e, "Why the driver complains here?");
DB.getConnection(name).setAutoCommit(false); } catch (Exception e) { Logger.error(e, "Why the driver complains here?");
/** * Execute an SQL query * * @param name * the DB name * @param SQL * the SQL statement * @return The rowSet of the query */ public static RowSet executeQuery(String name, String SQL) { Statement statement = null; ResultSet rs = null; try { statement = getConnection(name).createStatement(); if (statement != null) { rs = statement.executeQuery(SQL); } // Need to use a CachedRowSet that caches its rows in memory, which // makes it possible to operate without always being connected to // its data source CachedRowSet rowset = new CachedRowSetImpl(); rowset.populate(rs); return rowset; } catch (SQLException ex) { throw new DatabaseException(ex.getMessage(), ex); } finally { safeCloseResultSet(rs); safeCloseStatement(statement); } }