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.taobao.adfs.database.tdhsocket.client.util.ConvertUtil.java

public static double getDoubleFromString(String stringVal) throws SQLException {
    if (StringUtils.isBlank(stringVal)) {
        return 0;
    }//  w ww  . ja v  a2s.c o m
    try {
        return Double.parseDouble(stringVal);
    } catch (NumberFormatException e) {
        throw new SQLException("Parse integer error:" + stringVal);
    }
}

From source file:com.icbc.Scheduler.DA.PoolingConnectionProvider.java

private void initialize(String dbDriver, String dbURL, String dbUser, String dbPassword, int maxConnections,
        String dbValidationQuery) throws SQLException {
    if (dbDriver == null) {
        throw new SQLException("DB driver class name cannot be null!");
    }//from  w  ww . j ava2  s .  co m

    if (dbURL == null) {
        throw new SQLException("DB URL cannot be null!");
    }

    if (maxConnections < 0) {
        throw new SQLException("Max connections must be greater than zero!");
    }

    datasource = new BasicDataSource();
    datasource.setDriverClassName(dbDriver);
    datasource.setUrl(dbURL);
    datasource.setUsername(dbUser);
    datasource.setPassword(dbPassword);
    datasource.setMaxActive(maxConnections);
    datasource.setTestOnBorrow(true);
    //datasource.setLoginTimeout(5); 
    //        datasource.setLoginTimeout(-1);
    //        datasource.setMaxWait(-1);

    if (dbValidationQuery != null) {
        datasource.setValidationQuery(dbValidationQuery);
    } else {
        datasource.setValidationQuery("select SYSDATE FROM DUAL");
    }
}

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

private void initialiseDriver() throws SQLException {
    try {//ww  w .j  av a 2  s  . co m
        Class.forName(config.getDatabaseDriver());
    } catch (ClassNotFoundException e) {
        throw new SQLException(config.getDatabaseDriver() + " not found");
    }
    return;
}

From source file:net.ageto.gyrex.persistence.jdbc.pool.internal.PoolDataSource.java

@Override
public void setLogWriter(final PrintWriter out) throws SQLException {
    throw new SQLException("not allowed");
}

From source file:com.skycloud.management.portal.admin.sysmanage.dao.impl.UserManageDaoImpl.java

@Override
public int saveUser(final TUserBO user) throws SQLException {
    KeyHolder keyHolder = new GeneratedKeyHolder();
    final String sql = "insert into T_SCS_USER(" + "ID,ACCOUNT,PWD,NAME," + "DEPT_ID,ROLE_ID,EMAIL,PHONE,"
            + "MOBILE,FAX,POSITION,STATE," + "COMMENT,CHECK_CODE,IS_AUTO_APPROVE,CREATOR_USER_ID,"
            + "CREATE_DT,LASTUPDATE_DT,COMP_ID) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
    try {//from w w w.  ja v  a2s. com
        this.getJdbcTemplate().update(new PreparedStatementCreator() {
            int i = 1;

            @Override
            public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
                PreparedStatement ps = con.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
                ps.setInt(i++, user.getId());
                ps.setString(i++, user.getAccount());
                ps.setString(i++, user.getPwd());
                ps.setString(i++, user.getName());
                ps.setInt(i++, user.getDeptId());
                ps.setInt(i++, user.getRoleId());
                ps.setString(i++, user.getEmail());
                ps.setString(i++, user.getPhone());
                ps.setString(i++, user.getMobile());
                ps.setString(i++, user.getFax());
                ps.setString(i++, user.getPosition());
                ps.setInt(i++, user.getState());
                ps.setString(i++, user.getComment());
                ps.setString(i++, user.getCheckCode());
                ps.setInt(i++, user.getIsAutoApprove());
                ps.setInt(i++, user.getCreatorUserId());
                ps.setTimestamp(i++, new Timestamp(user.getCreateDt().getTime()));
                //update by CQ
                ps.setTimestamp(i++, new Timestamp(user.getLastupdateDt().getTime()));
                ps.setInt(i++, user.getCompId());
                return ps;
            }
        }, keyHolder);
    } catch (Exception e) {
        throw new SQLException("??" + user.getComment() + " ID"
                + user.getCreatorUserId() + " " + user.getCreateDt() + " "
                + e.getMessage());
    }
    return keyHolder.getKey().intValue();
}

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

public boolean dataDefinitionIgnoredInTransactions() throws SQLException {
    throw new SQLException("Unsupported TDDatabaseMetaData#dataDefinitionIgnoredInTransactions()");
}

From source file:com.softberries.klerk.dao.ProductDao.java

@Override
public void update(Product p) throws SQLException {
    try {/*from w ww . j  a v a2s. c o  m*/
        init();
        st = conn.prepareStatement(SQL_UPDATE_PRODUCT);
        st.setString(1, p.getCode());
        st.setString(2, p.getName());
        st.setString(3, p.getDescription());
        st.setLong(4, p.getId());
        // run the query
        int i = st.executeUpdate();
        System.out.println("i: " + i);
        if (i == -1) {
            System.out.println("db error : " + SQL_UPDATE_PRODUCT);
        }
        conn.commit();
    } catch (Exception e) {
        //rollback the transaction but rethrow the exception to the caller
        conn.rollback();
        e.printStackTrace();
        throw new SQLException(e);
    } finally {
        close(conn, st, generatedKeys);
    }
}

From source file:org.metis.jdbc.PreparedStmntCreator.java

private void bindObjects(PreparedStatement ps) throws SQLException {
    // bind the corresponding objects (if any)
    if (bindObs != null) {
        LOG.debug("setValues: binding this many objects " + bindObs.length);
        for (int i = 0; i < bindObs.length; i++) {
            try {
                ps.setObject(i + 1, bindObs[i]);
            } catch (Exception e) {
                String eStr = "setValues: caught this exception [" + e.getLocalizedMessage()
                        + "], when calling setObject for [" + bindObs[i].toString() + "]";
                LOG.error(eStr);/*from ww w .  ja va  2s . co m*/
                throw new SQLException(eStr);
            }
        }
    }
    return;
}

From source file:es.upm.fiware.rss.expenditureLimit.server.manager.common.test.FactoryResponseTest.java

/**
 * //from  w ww .  ja  v  a 2 s.  c om
 */
@Test
public void catchConnectionJDBCJson() throws Exception {
    UriInfo mockUriInfo = Mockito.mock(UriInfo.class);
    Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go"));
    JDBCConnectionException exception = new JDBCConnectionException("sql", new SQLException("reason"));
    Response bean = FactoryResponse.catchConnectionJDBCJson(mockUriInfo, exception, "resource", "txId");
    Assert.assertTrue(true);
}

From source file:com.dynamobi.db.conn.couchdb.CouchUdx.java

/**
 * Called by a custom LucidDB function for each view.
 * @param userName - CouchDB user name/*from w w  w  .  j  a  v a 2  s.com*/
 * @param pw - CouchDB password
 * @param url - CouchDB REST URL
 * @param view - CouchDB REST view -- concatenated on the end of URL with
 *               a slash prefix if necessary.
 * @param limit - Limit parameter passed to couchdb
 * @param reduce - if false, we pass &amp;reduce=false to the view.
 * @param groupLevel - sent to view for group reduction, default 'EXACT'
 * Possible values: 'EXACT', sends &amp;group=true.
 * 'NONE': sends &amp;group=false.
 * 1-N: sends &amp;group_level=x to the view or summarizer. 1 says to group
 * on the first index of the array key, 2 says the first two indexes,
 * N all indexes (equivalent to 'EXACT').
 *
 * (the following should be done in logic rewrite rule?) TODO:
 * 'CALCULATE': typically set by the pushdown optimizer, instructs
 * this udx to best-guess what group level we can/should push down.
 * The basic idea is that if the columns in a GROUP BY statement belong
 * to objects defined as elements of the key array for the first key-value
 * pair returned by a view, we will push down the number of columns being
 * grouped by and ignore the grouping on the LucidDB end. Otherwise all
 * group by's will still be done by LucidDB.
 * @param resultInserter - Table for inserting results. Assumed to have the
 * necessary column names in the order we get them.
 */
public static void query(String userName, String pw, String url, String view, String limit, boolean reduce,
        String groupLevel, boolean outputJson, PreparedStatement resultInserter) throws SQLException {

    // Specialize so we can column names for our resultInserter
    // instead of assuming an order.
    ParameterMetaData pmd = resultInserter.getParameterMetaData();
    FarragoParameterMetaData fpmd = (FarragoParameterMetaData) pmd;
    int paramCount = fpmd.getParameterCount();
    String[] paramNames = new String[paramCount];
    for (int i = 0; i < paramCount; i++) {
        paramNames[i] = fpmd.getFieldName(i + 1); // JDBC offset
    }

    RowProducer producer = new RowProducer();
    JSONParser parser = new JSONParser();

    InputStreamReader in = getViewStream(userName, pw, url, view, limit, reduce, groupLevel, true);

    while (!producer.isDone()) {
        try {
            parser.parse(in, producer, true);
        } catch (Throwable e) { // IOException, ParseException
            throw new SQLException(e);
        }

        if (!producer.getKey().equals("key"))
            continue;
        Object key = producer.getValue();

        try {
            parser.parse(in, producer, true);
        } catch (Throwable e) { // IOException, ParseException
            throw new SQLException(e);
        }

        assert (producer.getKey().equals("value"));
        Object value = producer.getValue();

        if (outputJson) {
            // put key in first col, val in second col, escape.
            resultInserter.setString(1, key.toString());
            resultInserter.setString(2, value.toString());
            resultInserter.executeUpdate();
            continue;
        }

        Map<String, Object> params = new HashMap<String, Object>(paramNames.length);
        int dupes = mergeParams(params, key, "KEY");
        dupes += mergeParams(params, value, "VALUE");

        if (params.size() - dupes != paramNames.length) {
            // We have more params than columns..
            throw new SQLException("Read " + params.size() + " params and " + paramNames.length
                    + " columns, which need to match. Did you " + "add column(s) for both the key and value?");
        }

        for (int c = 0; c < paramNames.length; c++) {
            Object o = params.get(paramNames[c]);
            if (o != null) {
                resultInserter.setObject(c + 1, o);
            }
        }

        resultInserter.executeUpdate();
    }
}