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:com.cws.esolutions.core.dao.impl.ServiceDataDAOImpl.java

/**
 * @see com.cws.esolutions.core.dao.interfaces.IServiceDataDAO#addService(java.util.List)
 *//*from  w  ww . j a v a2  s.c  o  m*/
public synchronized boolean addService(final List<String> data) throws SQLException {
    final String methodName = IServiceDataDAO.CNAME
            + "#addService(final List<String> data) throws SQLException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);

        for (Object str : data) {
            DEBUGGER.debug("Value: {}", str);
        }
    }

    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 addNewService(?, ?, ?, ?, ?, ?, ?, ?)}");
        stmt.setString(1, data.get(0)); // guid
        stmt.setString(2, data.get(1)); // serviceType
        stmt.setString(3, data.get(2)); // name
        stmt.setString(4, data.get(3)); // region
        stmt.setString(5, data.get(4)); // nwpartition
        stmt.setString(6, data.get(5)); // status
        stmt.setString(7, data.get(6)); // servers
        stmt.setString(8, data.get(7)); // description

        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.wso2telco.dbUtil.DataBaseConnectUtils.java

/**
 * Gets the connect db connection./*from   w  w w . j  a v a 2s  .  com*/
 *
 * @return the connect db connection
 * @throws SQLException                 the SQL exception
 * @throws CommonAuthenticatorException the authenticator exception
 */
private static Connection getConnectDBConnection() throws SQLException, NamingException {
    initializeConnectDatasource();

    if (mConnectDatasource != null) {
        return mConnectDatasource.getConnection();
    }
    throw new SQLException("Connect Datasource not initialized properly");
}

From source file:at.alladin.rmbt.db.dao.QoSTestResultDao.java

/**
 * //from  www . ja  v  a 2  s  .  c  o m
 * @param testUuid
 * @return
 * @throws SQLException
 */
public List<QoSTestResult> getByTestUid(Long testUid) throws SQLException {
    List<QoSTestResult> resultList = new ArrayList<>();

    try (PreparedStatement psGetAll = conn.prepareStatement(
            "SELECT nntr.uid, test_uid, success_count, failure_count, nnto.test, result AS result, "
                    + " nnto.results as results, qos_test_uid, nnto.test_desc, nnto.test_summary FROM qos_test_result nntr "
                    + " JOIN qos_test_objective nnto ON nntr.qos_test_uid = nnto.uid WHERE test_uid = ? AND nntr.deleted = 'FALSE' and nntr.implausible = 'FALSE'")) {
        psGetAll.setLong(1, testUid);

        if (psGetAll.execute()) {
            try (ResultSet rs = psGetAll.getResultSet()) {
                while (rs.next()) {
                    resultList.add(instantiateItem(rs));
                }
            }
        } else {
            throw new SQLException("item not found");
        }

        return resultList;
    }
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.BasicDataSourceWrapper.java

@SuppressWarnings("unchecked")
public <T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException {
    //    try { return (T) invokeMethod(basicDataSource != null?  basicDataSource : this, "unwrap", iface);
    try {//from w  w  w . jav a  2 s  .com
        return (T) invokeMethod(this, "unwrap", iface);
    } catch (Exception ex) {
        throw new SQLException(ex);
    }
}

From source file:com.taobao.tddl.common.mockdatasource.MockStatement.java

protected void checkClosed() throws SQLException {
    if (isClosed)
        throw new SQLException("closed");
}

From source file:com.gopivotal.cloudfoundry.test.core.DataSourceUtilsTest.java

@Test
public void checkAccessFailure() throws SQLException {
    when(this.testDataSource.getConnection()).thenReturn(this.testConnection);
    when(this.testConnection.prepareStatement("SELECT 1")).thenReturn(this.preparedStatement);
    when(this.preparedStatement.execute()).thenThrow(new SQLException("test message"));
    assertEquals("failed with test message", this.dataSourceUtils.checkAccess(this.testDataSource));
}

From source file:com.jaspersoft.jasperserver.api.engine.jasperreports.service.impl.SQLDataSourceWrapper.java

public boolean isWrapperFor(Class<?> iface) throws SQLException {
    try {//from  w  w  w  .j a va  2 s  .  com
        return (Boolean) invokeMethod(basicDataSource, "isWrapperFor", iface);
    } catch (Exception ex) {
        throw new SQLException(ex);
    }
}

From source file:gridool.db.partitioning.monetdb.MonetDBPrepareCopyIntoOperation.java

@Override
public Serializable execute() throws SQLException {
    final boolean firstTry = (createTableDDL != null);
    if (firstTry) {// prepare a table
        final Connection conn;
        try {//w w  w.  j  av a  2  s .co  m
            conn = getConnection();
        } catch (ClassNotFoundException e) {
            LOG.error(e);
            throw new SQLException(e.getMessage());
        }
        try {
            JDBCUtils.update(conn, createTableDDL);
        } catch (SQLException e) {
            conn.rollback();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Table already exists. Try to truncate " + tableName, e);
            }
            truncateTable(conn, tableName);
            // fall through
        }
    }

    prepareLoadFile(tableName, rowsData, !firstTry);
    this.rowsData = null;

    return Boolean.TRUE;
}

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

/**
 * @see com.cws.esolutions.core.dao.interfaces.IWebMessagingDAO#insertMessage(List)
 *//*from w  ww. j a va2  s .c om*/
public synchronized boolean insertMessage(final List<Object> messageList) throws SQLException {
    final String methodName = IWebMessagingDAO.CNAME
            + "#insertMessage(final List<Object> messageList) throws SQLException";

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

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

    try {
        sqlConn = dataSource.getConnection();

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

        sqlConn.setAutoCommit(true);
        stmt = sqlConn.prepareCall("{CALL submitSvcMessage(?, ?, ?, ?, ?, ?, ?, ?)}");
        stmt.setString(1, (String) messageList.get(0)); // message id
        stmt.setString(2, (String) messageList.get(1)); // message title
        stmt.setString(3, (String) messageList.get(2)); // message text
        stmt.setString(4, (String) messageList.get(3)); // author email
        stmt.setBoolean(5, (Boolean) messageList.get(4)); // is active
        stmt.setBoolean(6, (Boolean) messageList.get(5)); // is alert
        stmt.setBoolean(7, (Boolean) messageList.get(6)); // does expire
        stmt.setLong(8, (messageList.get(7) == null) ? 0 : (Long) messageList.get(7)); // expiry date

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

        if (DEBUG) {
            DEBUGGER.debug("isComplete: {}", isComplete);
        }
    } catch (SQLException sqx) {
        ERROR_RECORDER.error(sqx.getMessage(), 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.tern.db.db.java

public static Database establish(DataSource ds, String name) throws SQLException {
    if (name == null || name.length() <= 0) {
        name = "default";
    }/* ww  w  .  j av  a 2  s  .c o  m*/
    if (Database.dbs.containsKey(name)) {
        throw new SQLException("Has duplicate database name:" + name);
    }

    Connection con = null;
    String driverName = null;
    try {
        con = ds.getConnection();
        java.sql.DatabaseMetaData meta = con.getMetaData();
        driverName = meta.getDriverName();
    } catch (SQLException e) {
        Trace.write(Trace.Error, e, "Create database from DataSource");
    } finally {
        if (con != null) {
            try {
                con.close();
            } catch (java.sql.SQLException ex1) {
            }
        }
    }

    if (driverName == null) {
        return null;
    }

    Database d = null;

    if (driverName.indexOf("Oracle") >= 0) {
        d = new OracleDB();
    } else if (driverName.indexOf("mysql") >= 0) {
        d = new MySqlDB();
    } else {
        throw new SQLException("Unknown database driver:" + driverName);
    }

    d.ds = ds;

    if (Database.db == null) {
        Database.db = d;
    }

    Database.dbs.put(name, d);
    Trace.write(Trace.Running, "database added,name = %s,driver=%s", name, driverName);

    return d;
}