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.wso2telco.gsma.authenticators.DBUtils.java

/**
 * Gets the connect db connection.//from w  ww.  j a  va2s  .c om
 *
 * @return the connect db connection
 * @throws SQLException           the SQL exception
 * @throws AuthenticatorException the authenticator exception
 */
private static Connection getConnectDBConnection() throws SQLException, AuthenticatorException {
    initializeDatasources();

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

From source file:com.csc.fsg.life.dao.bo.AbstractBusinessObjectHandler.java

/**
   Called to handle a command. //w  w w . java  2s.c  o m
   Wraps the {@link #handle(AbstractBusinessObject, BusinessObjectCommand, Connection)} 
   method by creating a connection and ensuring the connection is closed.
   @param dataSource the dataSource.
   @throws BusinessObjectException If there is a business error with the command.
   @throws SQLException If there is an I/O error with the command.
**/
public void handle(DataSource dataSource) throws BusinessObjectException, SQLException {

    Connection conn = null;

    try {
        conn = dataSource.getConnection();

        // turn auto-commit off
        conn.setAutoCommit(false);

        // call the concrete classes handle method
        handle(bo, command, conn);

        // since we are successful, commit the transaction
        conn.commit();
    } catch (SQLException e) {
        if (conn != null)
            conn.rollback();
        throw new SQLException(exceptionHandler.getReadableMessage(e));
    } catch (BusinessObjectException e) {
        if (conn != null)
            conn.rollback();
        throw new BusinessObjectException(exceptionHandler.getReadableMessage(e));
    } catch (Exception e) {
        if (conn != null)
            conn.rollback();
        throw new BusinessObjectException(exceptionHandler.getReadableMessage(e));
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception cme) {
            logger.error("Connection close exception: " + cme.getMessage());
        }
    }

}

From source file:com.splout.db.common.SQLite4JavaManager.java

@Override
public String exec(String query) throws SQLException, JSONSerDeException {
    try {/*from w w w . j  a va 2s.c  o m*/
        db.get().exec(query);
        return "[{ \"status\": \"OK\" }]";
    } catch (SQLiteException e) {
        throw new SQLException(e);
    }
}

From source file:com.taobao.tddl.jdbc.atom.jdbc.TStatementWrapper.java

protected void recordReadTimes() throws SQLException {
    AtomDbStatusEnum status = datasourceWrapper.connectionProperties.dbStatus;
    if (status != AtomDbStatusEnum.R_STAUTS && status != AtomDbStatusEnum.RW_STATUS) {
        throw new SQLException("db do not allow to execute read ! dbStatus is " + status);
    }//from  w w w . ja  v a  2s  . co  m
    /*
    int readRestrictionTimes = datasourceWrapper.connectionProperties.readRestrictionTimes;
    int currentReadTimes = datasourceWrapper.readTimes.incrementAndGet();
    if (readRestrictionTimes != 0) {
       if (currentReadTimes > readRestrictionTimes) {
    datasourceWrapper.readTimesReject.incrementAndGet();
    throw new SQLException("max read times ," + currentReadTimes);
       }
    }
    */
    if (!datasourceWrapper.readFlowControl.allow()) {
        throw new SQLException(datasourceWrapper.readFlowControl.reportExceed());
    }
}

From source file:lcn.module.oltp.web.common.base.handler.AltibaseClobStringTypeHandler.java

protected Object getResultInternal(ResultSet rs, int index, LobHandler lobHandler) throws SQLException {

    StringBuffer read_data = new StringBuffer("");
    int read_length;

    char[] buf = new char[1024];

    Reader rd = lobHandler.getClobAsCharacterStream(rs, index);
    try {//from ww  w  .ja  va 2 s . c o  m
        while ((read_length = rd.read(buf)) != -1) {
            read_data.append(buf, 0, read_length);
        }
    } catch (IOException ie) {
        SQLException sqle = new SQLException(ie.getMessage());
        throw sqle;
        // 2011.10.10 ? ?
    } finally {
        if (rd != null) {
            try {
                rd.close();
            } catch (Exception ignore) {
                LOG.debug("IGNORE: " + ignore.getMessage());
            }
        }
    }

    return read_data.toString();

    //return lobHandler.getClobAsString(rs, index);
}

From source file:org.sakaiproject.orm.ibatis.support.BlobSerializableTypeHandler.java

protected Object getResultInternal(ResultSet rs, int index, LobHandler lobHandler)
        throws SQLException, IOException {

    InputStream is = lobHandler.getBlobAsBinaryStream(rs, index);
    if (is != null) {
        ObjectInputStream ois = new ObjectInputStream(is);
        try {//  w w w.j a  va 2  s .c  om
            return ois.readObject();
        } catch (ClassNotFoundException ex) {
            throw new SQLException("Could not deserialize BLOB contents: " + ex.getMessage());
        } finally {
            ois.close();
        }
    } else {
        return null;
    }
}

From source file:com.zotoh.core.db.JDBCPoolManager.java

private synchronized JDBCPool create(String pool, JDBCInfo param, Properties props) throws SQLException {
    if (existsPool(pool)) {
        throw new SQLException("Jdbc Pool already exists: " + pool);
    }/*w w  w.j  ava  2s .c o  m*/

    PoolableConnectionFactory pcf;
    DriverConnectionFactory dcf;
    GenericObjectPool gop;
    DBVendor dbv;
    ObjectPool p;
    Driver d;

    tlog().debug("JDBCPoolMgr: Driver : {}", param.getDriver());
    tlog().debug("JDBCPoolMgr: URL : {}", param.getUrl());

    //        Ute.loadDriver(param.getDriver());
    d = DriverManager.getDriver(param.getUrl());
    dbv = DBUte.getDBVendor(param);

    dcf = new DriverConnectionFactory(d, param.getUrl(), props);
    gop = new GenericObjectPool();
    gop.setMaxActive(asInt(props.getProperty("max-conns"), 10));
    gop.setTestOnBorrow(true);
    gop.setMaxIdle(gop.getMaxActive());
    gop.setMinIdle(asInt(props.getProperty("min-conns"), 2));
    gop.setMaxWait(asLong(props.getProperty("max-wait4-conn-millis"), 1500L));
    gop.setMinEvictableIdleTimeMillis(asLong(props.getProperty("evict-conn-ifidle-millis"), 300000L));
    gop.setTimeBetweenEvictionRunsMillis(asLong(props.getProperty("check-evict-every-millis"), 60000L));

    pcf = new PoolableConnectionFactory(dcf, gop, null, null, true, false);
    pcf.setDefaultReadOnly(false);
    p = pcf.getPool();

    JDBCPool j = new JDBCPool(dbv, param, p);
    _ps.put(pool, j);

    tlog().debug("JDBCPoolMgr: Added db pool: {}, info= {}", pool, param);
    return j;
}

From source file:com.splout.db.common.SQLiteJDBCManager.java

private static List<HashMap<String, Object>> convertResultSetToList(ResultSet rs, int maxResults)
        throws SQLException {
    ResultSetMetaData md = rs.getMetaData();
    int columns = md.getColumnCount();
    List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
    while (rs.next() && list.size() < maxResults) {
        HashMap<String, Object> row = new HashMap<String, Object>(columns);
        for (int i = 1; i <= columns; ++i) {
            row.put(md.getColumnName(i), rs.getObject(i));
        }//w ww.  j a  v  a  2s.  c  o  m
        list.add(row);
    }
    if (list.size() == maxResults) {
        throw new SQLException("Hard limit on number of results reached (" + maxResults
                + "), please use a LIMIT for this query.");
    }
    return list;
}

From source file:es.tid.fiware.rss.expenditureLimit.server.exceptionhandles.test.ExpenditureLimitExceptionMapperTest.java

@Test
public void toResponse() throws Exception {
    UriInfo mockUriInfo = Mockito.mock(UriInfo.class);
    Mockito.when(mockUriInfo.getAbsolutePath()).thenReturn(new URI("http://www.test.com/go"));
    ReflectionTestUtils.setField(mapper, "ui", mockUriInfo);

    RSSException e = new RSSException("RssException");
    Response response = mapper.toResponse(e);
    Assert.assertTrue(true);/* w  w  w.java  2 s  .  com*/

    GenericJDBCException ex = new GenericJDBCException("sql", new SQLException("reason"));
    response = mapper.toResponse(ex);
    Assert.assertTrue(true);

    JDBCConnectionException ex1 = new JDBCConnectionException("sql", new SQLException("reason"));
    response = mapper.toResponse(ex1);
    Assert.assertTrue(true);

    NotFoundException ex2 = new NotFoundException();
    response = mapper.toResponse(ex2);
    Assert.assertTrue(true);

    Exception ex3 = new Exception("RssException");
    response = mapper.toResponse(ex3);
    Assert.assertTrue(true);

    Exception ex4 = new Exception("RssException", ex);
    response = mapper.toResponse(ex4);
    Assert.assertTrue(true);

    Exception ex5 = new Exception("RssException", ex1);
    response = mapper.toResponse(ex5);
    Assert.assertTrue(true);

}

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

@Override
public void close() throws SQLException {
    if (fetchedRows != null) {
        try {/*from w  w w .  j  a  v  a  2s  .  c  o  m*/
            fetchedRows.getUnpacker().close();
            LOG.info("closed file based unpacker");
        } catch (IOException e) {
            throw new SQLException(e);
        }

        File f = fetchedRows.getFile();
        if (f != null) {
            // temp file is deleted
            String fname = f.getAbsolutePath();
            f.delete();
            LOG.info("deleted temp file: " + fname);
        }
    }

    // TODO #MN should check that this method is really called
    if (executor != null) {
        try {
            executor.shutdownNow();
        } catch (Throwable t) {
            throw new SQLException(t);
        } finally {
            executor = null;
        }
    }
}