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.jmstoolkit.pipeline.plugin.XMLValueTransformer.java

/**
 * @param inSql the sql to set//from   w  ww.jav a  2s.com
 * @throws SQLException if there's an error
 */
public final void setSql(final String inSql) throws SQLException {
    if (safe) {
        if (inSql != null && !"".equals(inSql)
                && inSql.toLowerCase(Locale.getDefault()).startsWith("select ")) {
            this.sql = inSql;
        } else {
            throw new SQLException("SQL statement must beging with 'select'.");
        }
    } else {
        this.sql = inSql;
    }
}

From source file:com.concursive.connect.web.modules.profile.dao.ProjectCategoryLogoFile.java

public boolean insert(Connection db) throws SQLException {
    boolean result = false;
    // The required linkModuleId
    linkModuleId = Constants.PROJECT_CATEGORY_FILES;
    // Determine if the database is in auto-commit mode
    boolean doCommit = false;
    try {/*from  w w w  .  j  a v a 2 s  .  c  o  m*/
        if (doCommit = db.getAutoCommit()) {
            db.setAutoCommit(false);
        }
        // Insert the record
        result = super.insert(db);
        // Update the referenced pointer
        if (result) {
            int i = 0;
            PreparedStatement pst = db.prepareStatement(
                    "UPDATE lookup_project_category " + "SET logo_id = ? " + "WHERE code = ? ");
            pst.setInt(++i, id);
            pst.setInt(++i, linkItemId);
            int count = pst.executeUpdate();
            result = (count == 1);
        }
        if (doCommit) {
            db.commit();
        }
    } catch (Exception e) {
        if (doCommit) {
            db.rollback();
        }
        throw new SQLException(e.getMessage());
    } finally {
        if (doCommit) {
            db.setAutoCommit(true);
        }
    }
    return result;
}

From source file:eionet.acl.PersistenceDB.java

/**
 * Checks ACL tables existance./*from   ww w . jav a 2s.  c  o m*/
 * @throws SQLException in case of different database errors: wrong configuration,
 *   database is down etc
 * @throws DbNotSupportedException if no ACL tables
 */
private void checkAclTables() throws SQLException, DbNotSupportedException {

    if (dbDriver == null && dataSource == null) {
        throw new SQLException("No Database Connection");
    }

    //boolean result = false;
    Connection conn = null;
    try {
        conn = getConnection();

        try {
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("select count(*) from ACLS");
            ResultSet rs2 = stmt.executeQuery("select count(*) from ACL_ROWS");
            //no tables assume ACLs in DB is not supported
        } catch (SQLException sqle) {
            throw new DbNotSupportedException("Error checking ACL tables " + sqle);
        }
    } finally {
        try {
            if (conn != null)
                conn.close();
        } catch (Exception e) {
            LOGGER.error("Error in closing connection " + e);
        }
    }

    //return result;
}

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

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

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

@Test
public void testProcessDumpExceptionNoState() throws SQLException {
    expectedEx.expect(SQLException.class);
    expectedEx.expectMessage("test");
    SQLUtils.processDumpException(new SQLException("test"));
}

From source file:com.tesora.dve.dbc.ServerDBConnection.java

public ResultSet executeQuery(String sql) throws SQLException {
    initialize();/*from  w  w w .  j  a v  a2 s .  c  o  m*/

    final MysqlTextResultChunkProvider resultConsumer = new MysqlTextResultChunkProvider();
    try {
        executeInContext(resultConsumer, sql.getBytes());
        return new DBCResultSet(resultConsumer, this);
    } catch (Throwable t) {
        throw new SQLException(t);
    } finally {
        ssCon.releaseNonTxnLocks();
    }
}

From source file:it.cnr.icar.eric.server.persistence.rdb.ConnectionPool.java

public Connection getConnection(String contextId) throws SQLException {
    try {/*from  ww w  . j  av  a2s. co  m*/
        //System.err.println("**********getConnection: contextId=" + contextId + " " + getStats());
        if ((maxConns < initConns) || (maxConns <= 0)) {
            throw new SQLException(
                    ServerResourceBundle.getInstance().getString("message.invalidSizeOfConnectionPool"));
        }

        if ((freeConnections.size() == 0) && (initConns != 0)) {
            // for some reasons the pool cannot be initialised
            throw new SQLException(ServerResourceBundle.getInstance().getString("message.noConnectionAvailable",
                    new Object[] { new Integer(freeConnections.size()), new Integer(initConns) }));
        }

        Connection conn = getConnection(contextId, timeOut * 1000);

        return conn;
    } catch (SQLException e) {
        log.trace(getStats());
        throw e;
    }
}

From source file:com.frameworkset.commons.dbcp2.PoolingDataSource.java

@Override
public <T> T unwrap(Class<T> iface) throws SQLException {
    throw new SQLException("PoolingDataSource is not a wrapper.");
}

From source file:com.eyeq.pivot4j.datasource.PooledOlapDataSource.java

/**
 * Note: Both 'userName' and 'password' are ignored.
 * // w  w  w .ja  v  a2s .c  o m
 * @see com.eyeq.pivot4j.datasource.AbstractOlapDataSource#createConnection(java.lang.String,
 *      java.lang.String)
 */
@Override
protected OlapConnection createConnection(String userName, String password) throws SQLException {
    try {
        return pool.borrowObject();
    } catch (SQLException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLException(e);
    }
}

From source file:org.h2gis.drivers.geojson.GeoJsonWriteDriver.java

/**
 * Write the spatial table to GeoJSON format.
 *
 * @param progress/* w ww.ja va 2s.  c  om*/
 * @throws SQLException
 */
private void writeGeoJson(ProgressVisitor progress) throws SQLException, IOException {
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(fileName);
        // Read Geometry Index and type
        final TableLocation parse = TableLocation.parse(tableName,
                JDBCUtilities.isH2DataBase(connection.getMetaData()));
        List<String> spatialFieldNames = SFSUtilities.getGeometryFields(connection, parse);
        if (spatialFieldNames.isEmpty()) {
            throw new SQLException(String.format("The table %s does not contain a geometry field", tableName));
        }

        // Read table content
        Statement st = connection.createStatement();
        try {
            JsonFactory jsonFactory = new JsonFactory();
            JsonGenerator jsonGenerator = jsonFactory.createGenerator(new BufferedOutputStream(fos),
                    JsonEncoding.UTF8);

            // header of the GeoJSON file
            jsonGenerator.writeStartObject();
            jsonGenerator.writeStringField("type", "FeatureCollection");
            writeCRS(jsonGenerator,
                    SFSUtilities.getAuthorityAndSRID(connection, parse, spatialFieldNames.get(0)));
            jsonGenerator.writeArrayFieldStart("features");

            ResultSet rs = st.executeQuery(String.format("select * from `%s`", tableName));

            try {
                ResultSetMetaData resultSetMetaData = rs.getMetaData();
                int geoFieldIndex = JDBCUtilities.getFieldIndex(resultSetMetaData, spatialFieldNames.get(0));

                cacheMetadata(resultSetMetaData);
                while (rs.next()) {
                    writeFeature(jsonGenerator, rs, geoFieldIndex);
                }
                progress.endStep();
                // footer
                jsonGenerator.writeEndArray();
                jsonGenerator.writeEndObject();
                jsonGenerator.flush();
                jsonGenerator.close();

            } finally {
                rs.close();
            }
        } finally {
            st.close();
        }
    } catch (FileNotFoundException ex) {
        throw new SQLException(ex);

    } finally {
        try {
            if (fos != null) {
                fos.close();
            }
        } catch (IOException ex) {
            throw new SQLException(ex);
        }
    }
}