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:net.ageto.gyrex.persistence.jdbc.pool.internal.PoolDataSourceFactory.java

@Override
public DataSource createDataSource(final Properties props) throws SQLException {
    final String poolId = props.getProperty(POOL_ID);
    if (!IdHelper.isValidId(poolId)) {
        throw new SQLException(
                String.format("invalid pool id '%s'; please use only a-z, 0-9, dot, dash and/or underscore",
                        String.valueOf(poolId)));
    }/*from ww w .  j  av  a 2 s  .com*/

    final String databaseName = props.getProperty(JDBC_DATABASE_NAME);
    if (StringUtils.isBlank(databaseName)) {
        throw new SQLException(String.format("property '%s' not set", JDBC_DATABASE_NAME));
    }

    // return data source
    return new PoolDataSource(poolId, databaseName, props.getProperty(JDBC_DATASOURCE_NAME),
            props.getProperty(JDBC_DESCRIPTION));
}

From source file:com.wso2telco.core.mnc.resolver.dao.OperatorDAO.java

public static Connection getDBConnection() throws SQLException, MobileNtException {
    initializeDatasources();//  w w w. j av a2 s  .co m

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

From source file:com.sf.ddao.factory.param.ForwardParameter.java

@Override
public int bindParam(PreparedStatement preparedStatement, int idx, Context context) throws SQLException {
    Object param = extractParam(context);
    if (param == null) {
        throw new SQLException("ParameterHandler '" + this.name + "' is not defined");
    }/*from w ww . j a  v a  2  s . c o  m*/
    StatementParamter statementParamter = (StatementParamter) param;
    return statementParamter.bindParam(preparedStatement, idx, context);
}

From source file:net.sf.hajdbc.codec.hex.HexCodecFactory.java

/**
 * {@inheritDoc}// w  w w  . j a va  2 s . co m
 * @see net.sf.hajdbc.codec.Codec#decode(java.lang.String)
 */
@Override
public String decode(String value) throws SQLException {
    try {
        return new String(Hex.decodeHex(value.toCharArray()));
    } catch (DecoderException e) {
        throw new SQLException(e);
    }
}

From source file:org.tec.webapp.jdbc.entity.support.IdentifierCallback.java

/** {@inheritDoc} */
@Override()/*from w  w w.j  a  v  a 2 s  .  c o m*/
public Long doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
    ResultSet generatedKeys = null;
    try {
        ps.execute();

        generatedKeys = ps.getGeneratedKeys();

        if (generatedKeys.next()) {
            return Long.valueOf(generatedKeys.getLong(1));
        } else {
            throw new SQLException("Unable to insert new record " + ps.toString());
        }
    } finally {
        if (generatedKeys != null) {
            generatedKeys.close();
        }
    }
}

From source file:com.iksgmbh.sql.pojomemodb.sqlparser.helper.OrderConditionParser.java

public List<OrderCondition> parseConditions(final String orderClause) throws SQLException {
    if (StringUtils.isEmpty(orderClause))
        throw new SQLException("No column defined for order by!");

    String unparsedRest = orderClause;
    if (unparsedRest.startsWith("(")) {
        unparsedRest = StringParseUtil.removeSurroundingPrefixAndPostFix(unparsedRest, "(", ")");
    }/*from  w w  w  .  j ava 2  s .c o m*/

    final List<OrderCondition> toReturn = new ArrayList<OrderCondition>();
    InterimParseResult parseResult = null;
    while (unparsedRest.length() > 0) {
        parseResult = StringParseUtil.parseNextValue(unparsedRest, StringParseUtil.COMMA);
        toReturn.add(parseOrderCondition(parseResult.parsedValue));
        unparsedRest = parseResult.unparsedRest;
    }

    return toReturn;
}

From source file:net.sf.hajdbc.codec.crypto.CipherCodec.java

/**
 * {@inheritDoc}/*from w  w w. ja v a2  s  .  c o  m*/
 * @see net.sf.hajdbc.codec.Codec#decode(java.lang.String)
 */
@Override
public String decode(String value) throws SQLException {
    try {
        Cipher cipher = Cipher.getInstance(this.key.getAlgorithm());

        cipher.init(Cipher.DECRYPT_MODE, this.key);

        return new String(cipher.doFinal(Base64.decodeBase64(value.getBytes())));
    } catch (GeneralSecurityException e) {
        throw new SQLException(e);
    }
}

From source file:com.wso2telco.historylog.DbTracelog.java

/**
 * Gets the mobile db connection./*ww  w  . j  a v a 2s . co m*/
 *
 * @return the mobile db connection
 * @throws SQLException        the SQL exception
 * @throws LogHistoryException the log history exception
 */
public static Connection getMobileDBConnection() throws SQLException, LogHistoryException {
    initializeDatasources();

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

From source file:com.sf.ddao.factory.param.ParameterHelper.java

public void appendParam(Context context, StringBuilder sb) throws SQLException {
    if (ref) {// w w w  .  j  a va 2 s.  c  om
        sb.append("?");
        return;
    }
    Object param = extractParam(context);
    if (param == null) {
        throw new SQLException("ParameterHandler '" + this.name + "' is not defined");
    }
    if (param instanceof StatementParamter) {
        StatementParamter statementParamter = (StatementParamter) param;
        statementParamter.appendParam(context, sb);
    } else {
        sb.append(param.toString());
    }
}

From source file:com.taobao.tdhs.jdbc.TDHSPreparedStatement.java

public TDHSPreparedStatement(Connection connection, TDHSClient client, String db, String sql)
        throws SQLException {
    super(connection, client, db);
    if (StringUtils.isBlank(sql)) {
        throw new SQLException("sql can't be null");
    }/*www.  j  a  va2 s . co m*/
    this.sql = StringUtils.trim(sql);
    this.sqlSplited = StringUtils.splitPreserveAllTokens(this.sql, "?");
    this.parameterNumber = sqlSplited.length - 1;
}