Java 8 Connection - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Connection class.

This code example shows how to use the following methods:close
    } 
 
    public void tearDown() throws Exception { 
        deleteTestTables(); 
        statement.close();
        conn.close();
        super.tearDown(); 
    } 
 
    private void createTestTables() { 
        try { 
            DatabaseMetaData meta = conn.getMetaData();
            ResultSet userTab = meta.getTables(null, null, null, null);
 
            while (userTab.next()) {
                String tableName = userTab.getString("TABLE_NAME");
                if (tableName.equals(DatabaseCreator.PARENT_TABLE)) {
                    statement
                            .execute(DatabaseCreator.DROP_TABLE_PARENT);
                } else if (tableName
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createStatement
	public void close() throws SQLException { 
		conn.close();
	} 
 
	public ResultSet executeQuery(String sql) throws SQLException {
		Statement stat = conn.createStatement();
		ResultSet rs = stat.executeQuery(sql);
		return rs;
	} 
 
	public int executeUpdate(String sql) throws SQLException {
		Statement stat = conn.createStatement();
		int affected_num = stat.executeUpdate(sql);
 
		if (stat != null) {
			stat.close();
		} 
		return affected_num;
	} 
} 
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close
  { 
    try 
    { 
      if(target != null)
      { 
        target.close();
      } 
    } 
    catch(SQLException ex)
    { 
      // Ignore this 
    } 
  } 
 
} 
9
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, prepareStatement
 
        try { 
            checkSystemVm(conn);
        } finally { 
            try { 
                conn.close();
            } catch (SQLException e) {
            } 
        } 
    } 
 
    protected void checkSystemVm(Connection conn) throws SQLException {
        PreparedStatement pstmt;
 
        pstmt = conn
                .prepareStatement("SELECT version FROM `cloud`.`version` ORDER BY id DESC LIMIT 1");
        ResultSet rs = pstmt.executeQuery();
        assert rs.next() : "No version selected";
        assert rs.getString(1).equals("3.0.0") : "VERSION stored is not 3.0.0: "
                + rs.getString(1);

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, commit, rollback
     
    /** {@inheritDoc} */ 
    public void close(TaskAttemptContext context) throws IOException {
      try { 
        statement.executeBatch();
        connection.commit();
      } catch (SQLException e) {
        try { 
          connection.rollback();
        } 
        catch (SQLException ex) {
          LOG.warn(StringUtils.stringifyException(ex));
        } 
        throw new IOException(e.getMessage());
      } finally { 
        try { 
          statement.close();
          connection.close();
        } 
        catch (SQLException ex) {

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:createStatement
 
    public void setUp() throws Exception { 
        super.setUp(); 
        Support_SQL.loadDriver(); 
        conn = Support_SQL.getConnection();
        statement = conn.createStatement();
        createTestTables(); 
 
    } 
 
    public void tearDown() throws Exception { 
        deleteTestTables(); 
        statement.close();
        conn.close();
        super.tearDown(); 
    } 
 
    public void createTestTables() { 
        try { 
            DatabaseMetaData meta = conn.getMetaData();
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepareStatement, x 1
    private String lastCheckId = "";
    private final String lastCheckFile = "/usr/local/libexec/sanity-check-last-id"; 
     
    private boolean checkMaxUsage(Connection conn) throws SQLException{
         
       PreparedStatement pstmt = conn.prepareStatement("SELECT value FROM `cloud`.`configuration` where name = 'usage.stats.job.aggregation.range'");
       ResultSet rs = pstmt.executeQuery();
        
       int aggregationRange = 1440; 
       if(rs.next()){
           aggregationRange = rs.getInt(1);
       } else { 
           System.out.println("Failed to retrieve aggregation range. Using default : "+aggregationRange);
       } 
        
       int aggregationHours = aggregationRange / 60;
        
       /* 
        * Check for usage records with raw_usage > aggregationHours 
        */ 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close
        } 
    } 
 
    public void tearDown() throws Exception { 
        deleteTestTables(); 
        conn.close();
        statement.close();
        super.tearDown(); 
    } 
 
    private void createTestTables() { 
        try { 
            ResultSet userTab = conn.getMetaData().getTables(null,
                    null, null, null); 
 
            while (userTab.next()) {
                String tableName = userTab.getString("TABLE_NAME");
                if (tableName.equals(DatabaseCreator.TEST_TABLE2)) {
                    statement.execute(DatabaseCreator.DROP_TABLE2);
                } else if (tableName
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, getAutoCommit, getTransactionIsolation, setAutoCommit, setTransactionIsolation
		Connection connection = this.pool.getConnection();
 
		// set the Transaction Isolation if defined 
		try { 
			// set the Transaction Isolation if defined 
			if ((this.isolation != null) && (connection.getTransactionIsolation() != this.isolation.intValue())) {
				connection.setTransactionIsolation (this.isolation.intValue());
			} 
 
			// toggle autoCommit to false if set 
			if ( connection.getAutoCommit() != this.autocommit ){
				connection.setAutoCommit(this.autocommit);
			} 
 
			return connection;
		} catch (SQLException e){
			try { 
				connection.close();
			} catch (Exception e2) {
				logger.warn("Setting connection properties failed and closing this connection failed again", e);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, getAutoCommit, rollback, setAutoCommit
		} 
		 
		Boolean autoCommit = null;
		try { 
			conn = config.getConnection();
			autoCommit = conn.getAutoCommit();
			config.setThreadLocalConnection(conn);
			conn.setTransactionIsolation(getTransactionLevel(config));	// conn.setTransactionIsolation(transactionLevel);
			conn.setAutoCommit(false);
			ai.invoke();
			conn.commit();
		} catch (NestedTransactionHelpException e) {
			if (conn != null) try {conn.rollback();} catch (Exception e1) {e1.printStackTrace();}
		} catch (Throwable t) {
			if (conn != null) try {conn.rollback();} catch (Exception e1) {e1.printStackTrace();}
			throw new ActiveRecordException(t);
		} 
		finally { 
			try { 
				if (conn != null) {

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Java 8 Connection Questions & Answers:

See Code Examples for Java 8 Connection Methods: