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

Source Link

Document

Constructs a SQLException object.

Usage

From source file:org.ff4j.test.audit.JdbcEventRepositoryTest.java

@Test(expected = FeatureAccessException.class)
public void testJdbcFeatureNamesKO() throws SQLException {
    JdbcEventRepository jrepo = (JdbcEventRepository) repo;
    DataSource mockDS = Mockito.mock(DataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDS).getConnection();
    jrepo.setDataSource(mockDS);/*from w  ww  .java 2s.  c o m*/
    jrepo.getFeatureNames();
}

From source file:com.wso2telco.workflow.dao.WorkflowStatsDbService.java

public void insertSubApprovalAuditRecord(SubscriptionApprovalAuditRecord record)
        throws SQLException, BusinessException {

    Connection conn = null;//from w ww .  j  a v  a2s . c o m
    PreparedStatement ps = null;
    try {
        conn = dbUtils.getDbConnection(DataSourceNames.WSO2AM_STATS_DB);
        StringBuilder query = new StringBuilder();
        query.append("INSERT INTO sub_approval_audit (API_PROVIDER, API_NAME, API_VERSION, APP_ID, ");
        query.append("SUB_STATUS, SUB_APPROVAL_TYPE, COMPLETED_BY_ROLE, COMPLETED_BY_USER) ");
        query.append("VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
        ps = conn.prepareStatement(query.toString());
        ps.setString(1, record.getApiProvider());
        ps.setString(2, record.getApiName());
        ps.setString(3, record.getApiVersion());
        ps.setInt(4, record.getAppId());
        ps.setString(5, record.getSubStatus());
        ps.setString(6, record.getSubApprovalType());
        ps.setString(7, record.getCompletedByRole());
        ps.setString(8, record.getCompletedByUser());
        ps.execute();

    } catch (SQLException e) {
        throw new SQLException();
    } catch (Exception e) {
        throw new BusinessException(GenaralError.UNDEFINED);
    } finally {
        dbUtils.closeAllConnections(ps, conn, null);
    }
}

From source file:lcn.module.batch.core.item.database.support.MethodMapItemPreparedStatementSetter.java

/**
 * params ? ? sqlType PreparedStatement? ??
 *//*from  w w  w. j a v  a 2s. co m*/
public void setValues(T item, PreparedStatement ps, String[] params, String[] sqlTypes,
        Map<String, Method> methodMap) throws SQLException {

    ReflectionSupport<T> reflector = new ReflectionSupport<T>();

    for (int i = 0; i < params.length; i++) {
        try {

            if (sqlTypes[i].equals("String")) {
                ps.setString(i + 1, (String) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("int")) {
                ps.setInt(i + 1, (Integer) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("double")) {
                ps.setDouble(i + 1, (Double) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("Date")) {
                ps.setDate(i + 1, (Date) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("byte")) {
                ps.setByte(i + 1, (Byte) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("short")) {
                ps.setShort(i + 1, (Short) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("boolean")) {
                ps.setBoolean(i + 1, (Boolean) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("long")) {
                ps.setLong(i + 1, (Long) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("Float")) {
                ps.setFloat(i + 1, (Float) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("BigDecimal")) {
                ps.setBigDecimal(i + 1, (BigDecimal) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("byte[]")) {
                ps.setBytes(i + 1, (byte[]) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else {
                throw new SQLException();
            }
        } catch (IllegalArgumentException e) {
            ReflectionUtils.handleReflectionException(e);
        }
    }
}

From source file:egovframework.rte.bat.core.item.database.support.EgovMethodMapItemPreparedStatementSetter.java

/**
 * params ? ? sqlType PreparedStatement? ??
 *//*from   w  w w .j a  v  a2  s  .  c om*/
public void setValues(T item, PreparedStatement ps, String[] params, String[] sqlTypes,
        Map<String, Method> methodMap) throws SQLException {

    EgovReflectionSupport<T> reflector = new EgovReflectionSupport<T>();

    for (int i = 0; i < params.length; i++) {
        try {

            if (sqlTypes[i].equals("String")) {
                ps.setString(i + 1, (String) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("int")) {
                ps.setInt(i + 1, (Integer) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("double")) {
                ps.setDouble(i + 1, (Double) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("Date")) {
                ps.setDate(i + 1, (Date) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("byte")) {
                ps.setByte(i + 1, (Byte) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("short")) {
                ps.setShort(i + 1, (Short) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("boolean")) {
                ps.setBoolean(i + 1, (Boolean) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("long")) {
                ps.setLong(i + 1, (Long) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("Float")) {
                ps.setFloat(i + 1, (Float) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("BigDecimal")) {
                ps.setBigDecimal(i + 1, (BigDecimal) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else if (sqlTypes[i].equals("byte[]")) {
                ps.setBytes(i + 1, (byte[]) reflector.invokeGettterMethod(item, params[i], methodMap));
            } else {
                throw new SQLException();
            }
        } catch (IllegalArgumentException e) {
            ReflectionUtils.handleReflectionException(e);
        }
    }
}

From source file:org.ff4j.test.audit.JdbcEventRepositoryTest.java

@Test(expected = FeatureAccessException.class)
public void testJdbcHitPieCharts() throws SQLException {
    JdbcEventRepository jrepo = (JdbcEventRepository) repo;
    DataSource mockDS = Mockito.mock(DataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDS).getConnection();
    jrepo.setDataSource(mockDS);//from  w  ww  . ja  v  a2s. c om
    jrepo.featuresListDistributionPie(0, 1);
}

From source file:org.ff4j.test.audit.JdbcEventRepositoryTest.java

@Test(expected = AuditAccessException.class)
public void testJdbcHitBarCharts() throws SQLException {
    JdbcEventRepository jrepo = (JdbcEventRepository) repo;
    DataSource mockDS = Mockito.mock(DataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDS).getConnection();
    jrepo.setDataSource(mockDS);/*w w  w  .j  a  v  a2s .  c om*/
    jrepo.getFeaturesUsageOverTime(Util.set("1"), 0, 1, 2);
}

From source file:io.cloudslang.content.database.utils.SQLUtilsTest.java

@Test
public void testProcessDumpExceptionNoMessage() throws SQLException {
    expectedEx.expect(SQLException.class);

    SQLException sqlException = new SQLException() {
        @Override//from  w w  w.ja  v  a2  s  . com
        public String getSQLState() {
            return SQL_STATE;
        }
    };
    SQLUtils.processDumpException(sqlException);
}

From source file:com.wso2telco.workflow.dao.WorkflowDbService.java

/**
 * Insert operator app endpoints./*from   w w  w . j  a  va2 s . c o  m*/
 *
 * @param appID            the app id
 * @param opEndpointIDList the op endpoint id list
 * @throws Exception the exception
 */

public void insertOperatorAppEndpoints(int appID, int[] opEndpointIDList)
        throws SQLException, BusinessException {

    Connection con = null;
    Statement st = null;

    try {
        con = DbUtils.getDbConnection(DataSourceNames.WSO2TELCO_DEP_DB);
        log.debug("opEndpointIDList.length : " + opEndpointIDList.length);
        con.setAutoCommit(false);
        st = con.createStatement();
        for (int i = 0; i < opEndpointIDList.length; i++) {
            if (opEndpointIDList[i] > 0 && !endpointAppsIsExist(opEndpointIDList[i], appID)) {
                StringBuilder query = new StringBuilder();
                query.append("INSERT INTO endpointapps (endpointid, applicationid, isactive) VALUES ");
                query.append("(" + opEndpointIDList[i] + "," + appID + ",0)");
                st.addBatch(query.toString());
            }
        }
        st.executeBatch();
        con.commit();

    } catch (SQLException e) {
        throw new SQLException();
    } catch (Exception e) {
        throw new BusinessException(GenaralError.UNDEFINED);
    } finally {
        DbUtils.closeAllConnections(st, con, null);
    }
}

From source file:org.ff4j.test.audit.JdbcEventRepositoryTest.java

@Test(expected = AuditAccessException.class)
public void testgetFeatureHitsPieKo() throws SQLException {
    JdbcEventRepository jrepo = (JdbcEventRepository) repo;
    DataSource mockDS = Mockito.mock(DataSource.class);
    Mockito.doThrow(new SQLException()).when(mockDS).getConnection();
    jrepo.setDataSource(mockDS);/*from   w  w w  .j a  v  a2s . c  o m*/
    jrepo.featureDistributionPie("f1", 0, 1);
}

From source file:com.adaptris.jdbc.connection.FailoverDatasourceTest.java

@Test
public void testExceptionWrappers() {
    assertEquals(SQLClientInfoException.class,
            wrapSQLClientInfoException(new SQLClientInfoException()).getClass());
    assertEquals(SQLClientInfoException.class, wrapSQLClientInfoException(new Exception()).getClass());
    assertEquals(SQLException.class, wrapSQLException(new Exception()).getClass());
    assertEquals(SQLException.class, wrapSQLException(new SQLException()).getClass());
}