Search in sources :

Example 1 with FBConnectionRequestInfo

use of org.firebirdsql.jca.FBConnectionRequestInfo in project jaybird by FirebirdSQL.

the class FBDataSource method getConnection.

/**
 * <p>Attempt to establish a database connection.
 *
 * @param username
 *         the database user on whose behalf the Connection is
 *         being made
 * @param password
 *         the user's password
 * @return a Connection to the database
 * @throws SQLException
 *         if a database-access error occurs.
 */
@SuppressWarnings("deprecation")
public Connection getConnection(String username, String password) throws SQLException {
    try {
        // mcf makes a copy for us.
        FBConnectionRequestInfo subjectCri = mcf.getDefaultConnectionRequestInfo();
        subjectCri.setUserName(username);
        subjectCri.setPassword(password);
        return (Connection) cm.allocateConnection(mcf, subjectCri);
    } catch (ResourceException re) {
        if (re.getCause() instanceof SQLException) {
            throw (SQLException) re.getCause();
        }
        if (re.getLinkedException() instanceof SQLException) {
            throw (SQLException) re.getLinkedException();
        }
        throw new FBSQLException(re);
    }
}
Also used : SQLException(java.sql.SQLException) FBConnectionRequestInfo(org.firebirdsql.jca.FBConnectionRequestInfo) Connection(java.sql.Connection) ResourceException(javax.resource.ResourceException)

Aggregations

Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 ResourceException (javax.resource.ResourceException)1 FBConnectionRequestInfo (org.firebirdsql.jca.FBConnectionRequestInfo)1