Example usage for java.sql SQLException SQLException

List of usage examples for java.sql SQLException SQLException

Introduction

In this page you can find the example usage for java.sql SQLException SQLException.

Prototype

public SQLException(String reason, String sqlState, Throwable cause) 

Source Link

Document

Constructs a SQLException object with a given reason, SQLState and cause.

Usage

From source file:com.nortal.petit.beanmapper.BeanMapper.java

private void mapProperty(ResultSet rs, B o, Property<B, Object> p) throws SQLException {
    try {/* ww  w .  java  2  s  . c  o  m*/
        p.write(o, resultSetReader.get(p.type(), rs, p.column()));
    } catch (RuntimeException e) {
        throw new RuntimeException(getErrorMsg(p, o), e);
    } catch (SQLException e) {
        throw new SQLException(getErrorMsg(p, o), e.getSQLState(), e.getErrorCode());
    }
}

From source file:com.alibaba.wasp.jdbcx.JdbcDataSource.java

private JdbcConnection getJdbcConnection(String user, char[] password) throws SQLException {
    Properties info = Utils.convertConfigurationToProperties(conf);
    info.setProperty("user", user);
    info.put("password", password);
    Connection conn = getConnectionInternal(getURL(url, true), info);
    if (conn == null) {
        throw new SQLException("No suitable driver found for " + url, "08001", 8001);
    } else if (!(conn instanceof JdbcConnection)) {
        throw new SQLException("Connecting with old version is not supported: " + url, "08001", 8001);
    }/*from w w w. j a  va  2 s  .c o  m*/
    return (JdbcConnection) conn;
}

From source file:com.alibaba.wasp.jdbcx.JdbcConnectionPool.java

/**
 * Retrieves a connection from the connection pool. If
 * <code>maxConnections</code> connections are already in use, the method
 * waits until a connection becomes available or <code>timeout</code> seconds
 * elapsed. When the application is finished using the connection, it must
 * close it in order to return it to the pool. If no connection becomes
 * available within the given timeout, an exception with SQL state 08001 and
 * vendor code 8001 is thrown.//  w w  w. ja va2 s .c o m
 * 
 * @return a new Connection object.
 * @throws java.sql.SQLException
 *           when a new connection could not be established, or a timeout
 *           occurred
 */
public Connection getConnection() throws SQLException {
    long max = System.currentTimeMillis() + timeout * 1000;
    do {
        synchronized (this) {
            if (activeConnections.get() < maxConnections) {
                return getConnectionNow();
            }
            try {
                wait(1000);
            } catch (InterruptedException e) {
                // ignore
            }
        }
    } while (System.currentTimeMillis() <= max);
    throw new SQLException("get connection timeout. activeConnections=" + activeConnections
            + ". maxConnections=" + maxConnections, "08001", 8001);
}