Java Code Examples for java.sql.Connection.setSchema()

The following are Jave code examples for showing how to use setSchema() of the java.sql.Connection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: uroborosql   File: JdbcConnectionSupplierImpl.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 *
 * @see jp.co.future.uroborosql.connection.ConnectionSupplier#getConnection()
 */
@Override
public Connection getConnection() {
	try {
		String jdbcUrl = props.get(PROPS_JDBC_URL);
		String jdbcUser = props.get(PROPS_JDBC_USER);
		String jdbcPassword = props.get(PROPS_JDBC_PASSWORD);

		Connection connection = DriverManager.getConnection(jdbcUrl, jdbcUser, jdbcPassword);

		String schema = getSchema();
		if (schema != null) {
			connection.setSchema(schema);
		}
		connection.setAutoCommit(getAutoCommit());
		connection.setReadOnly(getReadOnly());
		int transactionIsolation = getTransactionIsolation();
		if (transactionIsolation > 0) {
			connection.setTransactionIsolation(transactionIsolation);
		}
		return connection;
	} catch (SQLException ex) {
		ex.printStackTrace();
		return null;
	}
}
 
Example 2
Project: calcite-avatica   File: JdbcMeta.java   View Source Code Vote up 6 votes
protected void apply(Connection conn, ConnectionProperties connProps)
    throws SQLException {
  if (connProps.isAutoCommit() != null) {
    conn.setAutoCommit(connProps.isAutoCommit());
  }
  if (connProps.isReadOnly() != null) {
    conn.setReadOnly(connProps.isReadOnly());
  }
  if (connProps.getTransactionIsolation() != null) {
    conn.setTransactionIsolation(connProps.getTransactionIsolation());
  }
  if (connProps.getCatalog() != null) {
    conn.setCatalog(connProps.getCatalog());
  }
  if (connProps.getSchema() != null) {
    conn.setSchema(connProps.getSchema());
  }
}
 
Example 3
Project: cloud-s4-sdk-examples   File: SchemaPerTenantConnectionProvider.java   View Source Code Vote up 5 votes
@Override
public Connection getConnection(final String tenantIdentifier) throws SQLException {
    final Connection connection = this.getAnyConnection();
    try {
        connection.setSchema(TenantUtil.createSchemaName(tenantIdentifier));
    } catch (SQLException e) {
        throw new HibernateException("Could not alter JDBC connection to specified schema [" + tenantIdentifier + "]",
                e);
    }
    return connection;
}
 
Example 4
Project: cloud-s4-sdk-examples   File: SchemaPerTenantConnectionProvider.java   View Source Code Vote up 5 votes
@Override
public void releaseConnection(final String tenantIdentifier, final Connection connection) throws SQLException {
    try {
        connection.setSchema(TenantUtil.createSchemaName(defaultTenant));
    } catch (SQLException e) {
        throw new HibernateException("Could not alter JDBC connection to specified schema [" + tenantIdentifier + "]",
                e);
    }

    connection.close();
}