Example usage for java.sql SQLException toString

List of usage examples for java.sql SQLException toString

Introduction

In this page you can find the example usage for java.sql SQLException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.castor.cpa.persistence.sql.keygen.IdentityKeyGenerator.java

/**
 * {@inheritDoc}/*from w ww  . j  av a 2 s  . co m*/
 */
public Object generateKey(final Connection conn, final String tableName, final String primKeyName)
        throws PersistenceException {
    PreparedStatement stmt = null;
    ResultSet rs = null;

    try {
        // prepares the statement
        String sql = _factory.getIdentitySelectString(tableName, primKeyName);
        stmt = conn.prepareStatement(sql);

        // execute the prepared statement
        rs = stmt.executeQuery();

        // process result set using appropriate handler and return its value
        return _typeHandler.getValue(rs);
    } catch (SQLException e) {
        LOG.error("Problem generating new key", e);
        String msg = Messages.format("persist.keyGenSQL", this.getClass().getName(), e.toString());
        throw new PersistenceException(msg);
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException e) {
            LOG.warn("Problem closing JDBC statement", e);
        }
    }
}

From source file:com.boldust.general.LocalDAO.java

public synchronized void setString(int parameterIndex, String s, int psIndex) {

    try {/*from ww  w . j  av  a 2s  .c o m*/
        getPstmt(psIndex).setString(parameterIndex, s);
    } catch (SQLException sqle) {
        System.err.println(" pstmt.setString(parameterIndex, s) Fail! Error = " + sqle.toString()
                + " SQL state?" + getPstmt(psIndex).toString());
    } catch (Exception e) {
        System.err.println("Possibly null pointer in setInt");
    }
}

From source file:com.boldust.general.LocalDAO.java

public synchronized boolean executeUpdate(int psIndex) throws LocalDAOException {
    boolean flag = true;
    try {/*from w w w  .j  av a2 s.c om*/
        getPstmt(psIndex).executeUpdate();
        chmps.remove(psIndex);
    } catch (SQLException sqle) {
        flag = false;
        System.out.println("executeUpdate() Error!" + sqle.toString() + getPstmt(psIndex).toString());
        throw new LocalDAOException("SQL exception in dao.executeUpdate:", sqle);
    }
    return flag;

}

From source file:com.cloudera.sqoop.manager.TestSqlManager.java

@Test
public void testReadTable() {
    ResultSet results = null;//ww w.j ava2  s.co  m
    try {
        results = manager.readTable(HsqldbTestServer.getTableName(), HsqldbTestServer.getFieldNames());

        assertNotNull("ResultSet from readTable() is null!", results);

        ResultSetMetaData metaData = results.getMetaData();
        assertNotNull("ResultSetMetadata is null in readTable()", metaData);

        // ensure that we get the correct number of columns back
        assertEquals("Number of returned columns was unexpected!", metaData.getColumnCount(),
                HsqldbTestServer.getFieldNames().length);

        // should get back 4 rows. They are:
        // 1 2
        // 3 4
        // 5 6
        // 7 8
        // .. so while order isn't guaranteed, we should get back 16 on the left
        // and 20 on the right.
        int sumCol1 = 0, sumCol2 = 0, rowCount = 0;
        while (results.next()) {
            rowCount++;
            sumCol1 += results.getInt(1);
            sumCol2 += results.getInt(2);
        }

        assertEquals("Expected 4 rows back", EXPECTED_NUM_ROWS, rowCount);
        assertEquals("Expected left sum of 16", EXPECTED_COL1_SUM, sumCol1);
        assertEquals("Expected right sum of 20", EXPECTED_COL2_SUM, sumCol2);
    } catch (SQLException sqlException) {
        fail("SQL Exception: " + sqlException.toString());
    } finally {
        if (null != results) {
            try {
                results.close();
            } catch (SQLException sqlE) {
                fail("SQL Exception in ResultSet.close(): " + sqlE.toString());
            }
        }

        manager.release();
    }
}

From source file:com.boldust.general.LocalDAO.java

public synchronized void setBoolean(int parameterIndex, boolean flag, int psIndex) {
    try {/*from   w w w.java2  s .c o  m*/
        getPstmt(psIndex).setBoolean(parameterIndex, flag);
    } catch (SQLException sqle) {
        System.err.println(" pstmt.setBoolean(parameterIndex, flag) Fail! Error = " + sqle.toString());
    }

}

From source file:com.cloudera.sqoop.manager.CubridManagerExportTest.java

@After
public void tearDown() {
    super.tearDown();
    try {//  www  . java2s. co  m
        conn.close();
        manager.close();
    } catch (SQLException sqlE) {
        LOG.error("Got SQLException: " + sqlE.toString());
        fail("Got SQLException: " + sqlE.toString());
    }
}

From source file:com.cloudera.sqoop.manager.MySQLManager.java

@Override
public String[] listDatabases() {
    // TODO(aaron): Add an automated unit test for this.

    ResultSet results;/*ww  w  .  j av  a 2  s .  c o m*/
    try {
        results = execute("SHOW DATABASES");
    } catch (SQLException sqlE) {
        LOG.error("Error executing statement: " + sqlE.toString());
        release();
        return null;
    }

    try {
        ArrayList<String> databases = new ArrayList<String>();
        while (results.next()) {
            String dbName = results.getString(1);
            databases.add(dbName);
        }

        return databases.toArray(new String[0]);
    } catch (SQLException sqlException) {
        LOG.error("Error reading from database: " + sqlException.toString());
        return null;
    } finally {
        try {
            results.close();
        } catch (SQLException sqlE) {
            LOG.warn("Exception closing ResultSet: " + sqlE.toString());
        }

        release();
    }
}

From source file:com.cloudera.sqoop.manager.TestSqlManager.java

@Test
public void getPrimaryKeyFromTable() {
    // first, create a table with a primary key
    Connection conn = null;//from www.j  a v  a  2s. c  o  m
    try {
        conn = testServer.getConnection();
        PreparedStatement statement = conn.prepareStatement(
                "CREATE TABLE " + TABLE_WITH_KEY + "(" + KEY_FIELD_NAME + " INT NOT NULL PRIMARY KEY, foo INT)",
                ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
        statement.executeUpdate();
        statement.close();
    } catch (SQLException sqlException) {
        fail("Could not create table with primary key: " + sqlException.toString());
    } finally {
        if (null != conn) {
            try {
                conn.close();
            } catch (SQLException sqlE) {
                LOG.warn("Got SQLException during close: " + sqlE.toString());
            }
        }
    }

    String primaryKey = manager.getPrimaryKey(TABLE_WITH_KEY);
    assertEquals("Expected null pkey for table without key", primaryKey, KEY_FIELD_NAME);
}

From source file:com.redip.dao.impl.QualityNonconformitiesDocDAO.java

@Override
public List<QualityNonconformitiesDoc> getDocLink(int idQualityNonconformity) {
    List<QualityNonconformitiesDoc> nonconformitiesDoc = new ArrayList<QualityNonconformitiesDoc>();
    QualityNonconformitiesDoc ncDoc;/* w w  w. j  a  va 2s .  c o m*/
    StringBuilder query = new StringBuilder();
    query.append("SELECT idqualitynonconformitiesdoc, idqualitynonconformities, linktodoc ");
    query.append(" FROM qualitynonconformitiesdoc where idqualitynonconformities = '");
    query.append(idQualityNonconformity);
    query.append("'");

    Logger.log(QualityNonconformitiesDocDAO.class.getName(), Level.INFO,
            "Connecting to jdbc/qualityfollowup from getDocLink");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    ncDoc = new QualityNonconformitiesDoc();
                    ncDoc.setIdQualityNonconformitiesDoc(resultSet.getInt(1));
                    ncDoc.setIdQualityNonconformities(resultSet.getInt(2));
                    ncDoc.setLinkToDoc(resultSet.getString(3) == null ? "" : resultSet.getString(3));
                    nonconformitiesDoc.add(ncDoc);
                }
            } catch (SQLException exception) {
                Logger.log(QualityNonconformitiesDocDAO.class.getName(), Level.ERROR, exception.toString());
            } finally {
                resultSet.close();
            }

        } catch (SQLException exception) {
            Logger.log(QualityNonconformitiesDocDAO.class.getName(), Level.ERROR, exception.toString());
        } finally {
            preStat.close();
        }

    } catch (SQLException exception) {
        Logger.log(QualityNonconformitiesDocDAO.class.getName(), Level.ERROR, exception.toString());
    } finally {
        try {
            if (connection != null) {
                Logger.log(QualityNonconformitiesDocDAO.class.getName(), Level.INFO,
                        "Disconnecting to jdbc/qualityfollowup from getDocLink");
                connection.close();
            }
        } catch (SQLException e) {
            Logger.log(QualityNonconformitiesDocDAO.class.getName(), Level.WARN, e.toString());
        }
    }

    return nonconformitiesDoc;
}

From source file:org.bibsonomy.webapp.controller.admin.AdminRecommenderController.java

/**
 * Recommender Statuspage; get active recommenders from multiplexer and
 * fetch setting_id, rec_id, average latency from database; store in
 * command.recOverview// w  w  w.  j a  v a  2 s .c  o m
 */
private void showStatusTab(final AdminRecommenderViewCommand command) {
    final List<TagRecommender> recommenderList = new ArrayList<TagRecommender>();
    final List<RecAdminOverview> recommenderInfoList = new ArrayList<RecAdminOverview>();
    recommenderList.addAll(mp.getLocalRecommenders());
    recommenderList.addAll(mp.getDistRecommenders());

    for (final TagRecommender p : recommenderList) {
        try {
            final RecAdminOverview current = db
                    .getRecommenderAdminOverview(RecommenderUtil.getRecommenderId(p));
            current.setLatency(
                    db.getAverageLatencyForRecommender(current.getSettingID(), command.getQueriesPerLatency()));
            recommenderInfoList.add(current);
        } catch (final SQLException e) {
            log.debug(e.toString());
        }
    }
    /* Store info */
    command.setRecOverview(recommenderInfoList);
}