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(Throwable cause) 

Source Link

Document

Constructs a SQLException object with a given cause.

Usage

From source file:org.neo4j.jdbc.http.driver.CypherExecutor.java

/**
 * Commit the current transaction./*from w w  w  . j ava  2  s  .  c  o m*/
 *
 */
public void commit() throws SQLException {
    if (this.getOpenTransactionId() > 0) {
        HttpPost request = new HttpPost(currentTransactionUrl + "/commit");
        Neo4jResponse response = this.executeHttpRequest(request);
        if (response.hasErrors()) {
            throw new SQLException(response.displayErrors());
        }
        this.currentTransactionUrl = this.transactionUrl;
    }
}

From source file:uk.ac.kcl.rowmappers.DocumentRowMapper.java

@Override
public Document mapRow(ResultSet rs, int rowNum) throws SQLException {
    Document doc = new Document();
    if (reindex) {
        mapAssociativeArray(doc, rs);//from w  w w. j ava 2  s  .c  o  m
    } else {
        try {
            mapDBMetadata(doc, rs);
            mapDBFields(doc, rs);
        } catch (IOException e) {
            LOG.error("DocumentRowMapper could not map file based binary, nested exception: {}", e);
            throw new SQLException("DocumentRowMapper could not map file based binary");
        }
    }
    return doc;
}

From source file:com.orange.cepheus.broker.persistence.RegistrationsRepository.java

/**
 * Get registration/*from   ww w. j a  v  a2s .c  o  m*/
 * @param registrationId
 * @return registration
 * @throws RegistrationPersistenceException, EmptyResultDataAccessException
 */
public Registration getRegistration(String registrationId)
        throws RegistrationPersistenceException, EmptyResultDataAccessException {
    try {
        return jdbcTemplate.queryForObject(
                "select expirationDate, registerContext from t_registrations where id=?",
                new Object[] { registrationId }, (ResultSet rs, int rowNum) -> {
                    Registration registration = new Registration();
                    try {
                        registration.setExpirationDate(Instant.parse(rs.getString("expirationDate")));
                        registration.setRegisterContext(
                                mapper.readValue(rs.getString("registerContext"), RegisterContext.class));
                    } catch (IOException e) {
                        throw new SQLException(e);
                    }
                    return registration;
                });
    } catch (EmptyResultDataAccessException e) {
        throw e;
    } catch (DataAccessException e) {
        throw new RegistrationPersistenceException(e);
    }
}

From source file:dbutils.DbUtilsTemplate.java

public void fillStatement(PreparedStatement stmt, Object... params) throws SQLException {

    // check the parameter count, if we can
    ParameterMetaData pmd = null;
    if (!pmdKnownBroken) {
        pmd = stmt.getParameterMetaData();
        int stmtCount = pmd.getParameterCount();
        int paramsCount = params == null ? 0 : params.length;

        if (stmtCount != paramsCount) {
            throw new SQLException(
                    "Wrong number of parameters: expected " + stmtCount + ", was given " + paramsCount);
        }// w  w  w  .  j  av  a2  s  .co  m
    }

    // nothing to do here
    if (params == null) {
        return;
    }

    for (int i = 0; i < params.length; i++) {
        if (params[i] != null) {
            stmt.setObject(i + 1, params[i]);
        } else {
            // VARCHAR works with many drivers regardless
            // of the actual column type. Oddly, NULL and
            // OTHER don't work with Oracle's drivers.
            int sqlType = Types.VARCHAR;
            if (!pmdKnownBroken) {
                try {
                    /*
                     * It's not possible for pmdKnownBroken to change from
                     * true to false, (once true, always true) so pmd cannot
                     * be null here.
                     */
                    sqlType = pmd.getParameterType(i + 1);
                } catch (SQLException e) {
                    pmdKnownBroken = true;
                }
            }
            stmt.setNull(i + 1, sqlType);
        }
    }
}

From source file:com.cws.esolutions.security.dao.usermgmt.impl.SQLUserManager.java

/**
 * @see com.cws.esolutions.security.dao.usermgmt.interfaces.UserManager#addUserAccount(java.util.List, java.util.List)
 */// w  ww. j a  v  a2  s  . c  o m
public synchronized boolean addUserAccount(final List<String> userAccount, final List<String> roles)
        throws UserManagementException {
    final String methodName = SQLUserManager.CNAME
            + "#addUserAccount(final List<String> userAccount, final List<String> roles) throws UserManagementException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", userAccount);
        DEBUGGER.debug("Value: {}", roles);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = SQLUserManager.dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        stmt = sqlConn.prepareCall("{ CALL addUserAccount(?, ?, ?, ?, ?, ?, ?, ?) }");
        stmt.setString(1, userAccount.get(0)); // guid
        stmt.setString(2, userAccount.get(1)); // username
        stmt.setString(3, userAccount.get(2)); // password
        stmt.setBoolean(4, Boolean.valueOf(userAccount.get(3))); // suspended
        stmt.setString(5, userAccount.get(4)); // surname
        stmt.setString(6, userAccount.get(5)); // givenname
        stmt.setString(7, userAccount.get(6)); // displayname
        stmt.setString(8, userAccount.get(7)); // email

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        if (!(stmt.execute())) {
            isComplete = true;
        }
    } catch (SQLException sqx) {
        throw new UserManagementException(sqx.getMessage(), sqx);
    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }

            if (!(sqlConn == null) && (!(sqlConn.isClosed()))) {
                sqlConn.close();
            }
        } catch (SQLException sqx) {
            throw new UserManagementException(sqx.getMessage(), sqx);
        }
    }

    return isComplete;
}

From source file:FacultyAdvisement.StudentRepository.java

public static void update(DataSource ds, Student student) throws SQLException {
    String studentSQL = "UPDATE STUDENT SET STUID = ?, FIRSTNAME = ?, LASTNAME = ?, MAJORCODE = ?, PHONE = ? WHERE EMAIL = ?";

    if (ds == null) {
        throw new SQLException("ds is null; Can't get data source");
    }/*from   w ww .j av  a2s  . c  o  m*/

    Connection conn = ds.getConnection();

    if (conn == null) {
        throw new SQLException("conn is null; Can't get db connection");
    }

    try {
        //Student Information
        PreparedStatement sqlStatement = conn.prepareStatement(studentSQL);
        sqlStatement.setString(1, student.getId());
        sqlStatement.setString(2, student.getFirstName());
        sqlStatement.setString(3, student.getLastName());
        sqlStatement.setString(4, student.getMajorCode());
        sqlStatement.setString(5, student.getPhoneNumber());
        sqlStatement.setString(6, student.getUsername());

        sqlStatement.executeUpdate();

    } finally {
        conn.close();
    }
}

From source file:com.dsf.dbxtract.cdc.journal.JournalExecutor.java

private void copyResultsetToMap(ResultSet rs, List<Map<String, Object>> result) throws SQLException {

    if (rs == null)
        throw new SQLException("result is null");
    if (result == null)
        throw new NullPointerException("result map is null");

    while (rs.next()) {
        if (journalColumns == null) {
            journalColumns = new ArrayList<>();
            for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
                journalColumns.add(rs.getMetaData().getColumnLabel(i + 1).toLowerCase());
            }/*from  w  w  w. jav  a  2  s.  com*/
        }
        Map<String, Object> map = new HashMap<>();
        for (String col : journalColumns) {
            map.put(col, rs.getObject(col));
        }
        result.add(map);
    }
}

From source file:com.cws.esolutions.core.dao.impl.ServiceDataDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IServiceDataDAO#removeService(java.lang.String)
 *//*from  w  w  w. j ava 2s.  c  o m*/
public synchronized boolean removeService(final String datacenter) throws SQLException {
    final String methodName = IServiceDataDAO.CNAME
            + "#removeService(final String datacenter) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", datacenter);
    }

    Connection sqlConn = null;
    boolean isComplete = false;
    CallableStatement stmt = null;

    try {
        sqlConn = dataSource.getConnection();

        if (sqlConn.isClosed()) {
            throw new SQLException("Unable to obtain application datasource connection");
        }

        sqlConn.setAutoCommit(true);

        stmt = sqlConn.prepareCall("{CALL removeServiceData(?)}");
        stmt.setString(1, datacenter);

        if (DEBUG) {
            DEBUGGER.debug("CallableStatement: {}", stmt);
        }

        isComplete = (!(stmt.execute()));

        if (DEBUG) {
            DEBUGGER.debug("isComplete: {}", isComplete);
        }
    } catch (SQLException sqx) {
        throw new SQLException(sqx.getMessage(), sqx);
    } finally {
        if (stmt != null) {
            stmt.close();
        }

        if ((sqlConn != null) && (!(sqlConn.isClosed()))) {
            sqlConn.close();
        }
    }

    return isComplete;
}

From source file:com.treasuredata.jdbc.TDDatabaseMetaData.java

public ResultSet getClientInfoProperties() throws SQLException {
    throw new SQLException("Unsupported TDDatabaseMetaData#getClientInfoProperties()");
}

From source file:QueryRunner.java

/**
 * Fill the <code>PreparedStatement</code> replacement parameters with 
 * the given objects.//from  w ww  .j a v a2 s.  c o m
 * @param stmt PreparedStatement to fill
 * @param params Query replacement parameters; <code>null</code> is a valid
 * value to pass in.
 * @throws SQLException if a database access error occurs
 */
public void fillStatement(PreparedStatement stmt, Object[] params) throws SQLException {

    if (params == null) {
        return;
    }

    ParameterMetaData pmd = stmt.getParameterMetaData();
    if (pmd.getParameterCount() < params.length) {
        throw new SQLException(
                "Too many parameters: expected " + pmd.getParameterCount() + ", was given " + params.length);
    }
    for (int i = 0; i < params.length; i++) {
        if (params[i] != null) {
            stmt.setObject(i + 1, params[i]);
        } else {
            // VARCHAR works with many drivers regardless
            // of the actual column type.  Oddly, NULL and 
            // OTHER don't work with Oracle's drivers.
            int sqlType = Types.VARCHAR;
            if (!pmdKnownBroken) {
                try {
                    sqlType = pmd.getParameterType(i + 1);
                } catch (SQLException e) {
                    pmdKnownBroken = true;
                }
            }
            stmt.setNull(i + 1, sqlType);
        }
    }
}