Example usage for java.sql SQLException printStackTrace

List of usage examples for java.sql SQLException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.iucosoft.eavertizare.dao.impl.ClientsDaoImpl.java

@Override
public void createTabeleClienti(Firma firma) {

    try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement();) {

        String queryLocal = "CREATE TABLE " + firma.getTabelaClientiLocal() + " " + "(id INT NOT NULL, "
                + " nume VARCHAR(45), " + " prenume VARCHAR(45), " + " nr_telefon INT, "
                + " email VARCHAR(45), " + " data_expirare DATE, " + " id_firma INT, " + " trimis TINYINT(1), "
                + " PRIMARY KEY ( id ))";

        stmt.executeUpdate(queryLocal);/*from   w  ww  . j a va  2  s  . co  m*/

    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:gov.nih.nci.cacisweb.dao.virtuoso.VirtuosoCommonUtilityDAO.java

/**
 * Gets the next sequence by suffixing '_SEQ' to the table name
 * //ww w.  j  a v  a2  s. com
 * @param tableName
 * @return
 * @throws DAOException
 */
public long getNextSequenceBySequenceName(String sequenceName) throws DAOException {
    log.debug("getNextSequenceByTableName(String sequenceName) - start");
    long sequenceNum = 0;
    StringBuffer sequenceSQL = new StringBuffer();
    sequenceSQL.append("SELECT " + sequenceName + ".nextval from dual");
    try {
        pstmt = new LoggableStatement(cacisConnection, sequenceSQL.toString());
        log.info("SQL getNextSequenceByTableName(String sequenceName) : " + pstmt.toString());
        ResultSet rs = pstmt.executeQuery();
        if (rs.next()) {
            sequenceNum = rs.getLong("NEXTVAL");
        }
    } catch (SQLException sqle) {
        log.error(sqle.getMessage());
        sqle.printStackTrace();
        throw new DAOException(sqle.getMessage());
    }
    return sequenceNum;
}

From source file:eu.optimis.aggregator.test.AggregatorPushTest.java

private int getResourceQueryCount(String query) {
    DBConnection dbconn = new DBConnection();
    Connection conn = dbconn.getConnection();
    int count = 0;
    try {/*from   w w  w  .  ja v  a  2  s .  c om*/
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(query);
        rs.next();
        count = rs.getInt("COUNT");
    } catch (SQLException e) {
        e.printStackTrace();
        logger.error("SQLException:" + e.getMessage() + ":" + e.getSQLState());
    } finally {
        try {
            conn.close();
        } catch (Exception e) {
        }
    }
    return count;
}

From source file:com.iucosoft.eavertizare.dao.impl.ClientsDaoImpl.java

@Override
public Client findClient(Firma firma, String nume) {
    String query = "select * from " + firma.getTabelaClientiLocal() + " where nume='" + nume + "'";
    Client client = null;/*  w  w w .  ja v a 2  s . c o m*/

    try (Connection con = dataSource.getConnection();
            PreparedStatement ps = con.prepareStatement(query);
            ResultSet rs = ps.executeQuery();) {

        if (rs.next()) {
            client = new Client(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getString(5),
                    rs.getDate(6), firma, rs.getBoolean(8));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return client;
}

From source file:com.iucosoft.eavertizare.dao.impl.ClientsDaoImpl.java

@Override
public Client findClient(Firma firma, String nume, String prenume) {
    String query = "select * from " + firma.getTabelaClientiLocal() + " where nume='" + nume + "' and prenume='"
            + prenume + "'";
    Client client = null;/*from  ww  w.j  av a 2  s. c  o m*/

    try (Connection con = dataSource.getConnection();
            PreparedStatement ps = con.prepareStatement(query);
            ResultSet rs = ps.executeQuery();) {

        if (rs.next()) {
            client = new Client(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getString(5),
                    rs.getDate(6), firma, rs.getBoolean(8));
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return client;
}

From source file:fr.calamus.common.db.core.DbPool.java

public Connection createCnx() {
    try {/*from  w w w . j a  v a  2 s  .c om*/
        return DriverManager.getConnection(dbUrl);
    } catch (SQLException ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:fr.calamus.common.db.core.DbPool.java

public void closeTransactionMode(String key) {
    transactionCnxKeys.remove(key);/*  w  ww.  j a  v a 2 s.c om*/
    try {
        getCnx(key).close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
}

From source file:org.castor.jpa.functional.AbstractSpringBaseTest.java

protected final void verifyPersistentBook(Book book) throws SQLException {
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;//w  w  w  .j  av a2s . co  m

    int fetchSize = 0;
    long isbn = 0;
    String title = null;

    try {
        // Load the book from the database.
        connection = this.dataSource.getConnection();
        preparedStatement = connection.prepareStatement("SELECT isbn, title FROM book WHERE isbn = ?");
        preparedStatement.setObject(1, Long.valueOf(book.getIsbn()));
        resultSet = preparedStatement.executeQuery();

        fetchSize = resultSet.getFetchSize();
        resultSet.next();

        // Get values from result set.
        isbn = resultSet.getLong(1);
        title = resultSet.getString(2);

    } catch (SQLException e) {
        fail("Could not verify book instance: " + e.getMessage());
        e.printStackTrace();
    } finally {
        // Release resources.
        resultSet.close();
        preparedStatement.close();
        connection.close();
    }

    // Verify result.
    assertEquals(1, fetchSize);
    assertEquals(book.getIsbn(), isbn);
    assertEquals(book.getTitle(), title);
}

From source file:org.projecthdata.ehr.viewer.activities.EhrActivity.java

private void clearAllData() {
    try {/*from w  w  w .  j  a va 2  s .c o  m*/
        Dao<WeightReading, Integer> dao = ehrDatabaseHelper.getWeightReadingDao();
        dao.delete(dao.deleteBuilder().prepare());

        Editor editor = prefs.edit();
        editor.remove(Constants.PREF_PATIENT_NAME_LASTNAME).remove(Constants.PREF_PATIENT_NAME_GIVEN)
                .remove(Constants.PREF_PATIENT_NAME_SUFFIX).remove(Constants.PREF_PATIENT_ID).commit();
        editor.remove(Constants.PREF_EHR_URL).commit();
        editor.remove(Constants.PREF_WEIGHT_SYNC_STATE).commit();
        editor.remove(Constants.PREF_ROOT_SYNC_STATE).commit();
        editor.remove(Constants.PREF_PATIENT_INFO_SYNC_STATE).commit();
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

From source file:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getUsage(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.metrics.HistogramIntervalType, org.joda.time.DateTime, org.joda.time.DateTime)
 *//*from   w  w w  .  j av a2  s . com*/
@Override
public UsageHistogramBean getUsage(String organizationId, String apiId, String version,
        HistogramIntervalType interval, DateTime from, DateTime to) {
    UsageHistogramBean rval = new UsageHistogramBean();
    Map<Long, UsageDataPoint> index = generateHistogramSkeleton(rval, from, to, interval, UsageDataPoint.class,
            Long.class);

    try {
        QueryRunner run = new QueryRunner(ds);
        String gbColumn = groupByColumn(interval);
        String sql = "SELECT " + gbColumn //$NON-NLS-1$
                + ", count(*) FROM gw_requests WHERE api_org_id = ? AND api_id = ? AND api_version = ? AND rstart >= ? AND rstart < ? GROUP BY " //$NON-NLS-1$
                + gbColumn;
        ResultSetHandler<UsageHistogramBean> handler = new UsageHistogramHandler(rval, index);
        run.query(sql, handler, organizationId, apiId, version, from.getMillis(), to.getMillis());
    } catch (SQLException e) {
        e.printStackTrace();
    }

    return rval;
}