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:io.apiman.manager.api.jdbc.JdbcMetricsAccessor.java

/**
 * @see io.apiman.manager.api.core.IMetricsAccessor#getResponseStats(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   ww  w.jav a  2  s  .  co m
@Override
public ResponseStatsHistogramBean getResponseStats(String organizationId, String apiId, String version,
        HistogramIntervalType interval, DateTime from, DateTime to) {
    ResponseStatsHistogramBean rval = new ResponseStatsHistogramBean();
    Map<Long, ResponseStatsDataPoint> index = generateHistogramSkeleton(rval, from, to, interval,
            ResponseStatsDataPoint.class, Long.class);

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

    return rval;
}

From source file:desktop.olayinka.file.transfer.model.DerbyJDBCHelper.java

public void onStart(Connection mConnection) {
    Statement statement = null;/*  w  w  w  . ja va2s.  c  o m*/
    ResultSet resultSet = null;
    try {
        statement = mConnection.createStatement();
        resultSet = statement.executeQuery("SELECT * FROM  app_info");
        resultSet.next();
        mCurrentVersion = resultSet.getLong(1);
        cleanUp(statement, resultSet);
    } catch (SQLException e) {
        e.printStackTrace();
        cleanUp(statement, resultSet);
        try {
            statement = mConnection.createStatement();

            InputStream in = DerbyJDBCHelper.class.getResourceAsStream("/raw/db.sql");
            String[] queries = IOUtils.toString(in).split(";");
            for (String query : queries) {
                query = query.trim();
                if (!query.isEmpty()) {
                    statement.execute(query);
                }
            }

            mConnection.commit();

            mCurrentVersion = 1;

            cleanUp(statement, null);
        } catch (SQLException | IOException e1) {
            e1.printStackTrace();
            cleanUp(statement, null);
            System.exit(1);
        }
    }

}

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

public void commitTransaction(String key) {
    try {/*from w w w  .j  a va  2  s  .  c  o m*/
        Statement st = getStatement(key);
        if (st == null || st.isClosed()) {
            st = createStatement(key);
        }
        st.execute("commit");
        transactionCnxKeys.remove(key);
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    //closeStatement();
}

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

private Statement getStatement(String key) {
    try {//from   w w w .  java  2s .  c  om
        Statement st = stMap.get(key);
        if (st == null || st.isClosed()) {
            log("creating statement");
            st = createStatement(key);
        } else {
            log("returning existing statement " + st.getQueryTimeout());
        }
        return st;
    } catch (SQLException ex) {
        ex.printStackTrace();
        return null;
    }
}

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

@Override
public List<Client> findAllClientsForFirmaRemote(Firma firma) {

    DriverManagerDataSource dataSourceClient = new DriverManagerDataSource();
    dataSourceClient.setDriverClassName(firma.getConfiguratii().getDriver());
    dataSourceClient.setUrl(firma.getConfiguratii().getUrlDb());
    dataSourceClient.setUsername(firma.getConfiguratii().getUsername());
    dataSourceClient.setPassword(firma.getConfiguratii().getPassword());

    String query = "select * from " + firma.getConfiguratii().getTabelaClienti();
    List<Client> clientsList = new ArrayList<>();

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

        while (rs.next()) {
            Client client = new Client();
            client.setId(rs.getInt(1));/* ww w  .j  av  a  2  s . c om*/
            client.setNume(rs.getString(2));
            client.setPrenume(rs.getString(3));
            client.setNrTelefon(rs.getInt(4));
            client.setEmail(rs.getString(5));
            client.setDateExpirare(rs.getTimestamp(6));
            clientsList.add(client);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return clientsList;
}

From source file:de.tudarmstadt.lt.nlkg.DT.java

public Entry get(String word, int max_dt_words) {
    try {//from w w  w  .  j  ava  2  s. c  om
        String query = String.format(
                "SELECT word2,count FROM `dt` WHERE word1 LIKE '%s' ORDER BY count DESC LIMIT %d;", word,
                max_dt_words + 1);
        final Connection c = connect();
        final Statement s = c.createStatement();
        final ResultSet r = s.executeQuery(query);

        if (!r.next())
            return Entry.EMPTY;
        Entry result = new Entry() {
            {
                word = new Word() {
                    {
                        word = r.getString(1);
                        significance = r.getDouble(2);
                    }
                };
                dtwords = new Iterator<Word>() {
                    @Override
                    public boolean hasNext() {
                        try {
                            if (r.isClosed())
                                return false;
                            if (r.next())
                                return true;
                            r.close();
                            s.close();
                            return false;
                        } catch (SQLException e) {
                            e.printStackTrace();
                            return false;
                        }
                    }

                    @Override
                    public Word next() {
                        try {
                            return new Word() {
                                {
                                    word = r.getString(1);
                                    significance = r.getDouble(2);
                                }
                            };
                        } catch (SQLException e) {
                            e.printStackTrace();
                            return Word.EMPTY;
                        }
                    }

                    @Override
                    public void remove() {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    protected void finalize() throws Throwable {
                        r.close();
                        r.close();
                        super.finalize();
                    }
                };
            }
        };
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        return Entry.EMPTY;
    }

}

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

@Override
public List<Client> findAllClientsForFirmaLocal(Firma firma) {

    String query = "select * from " + firma.getTabelaClientiLocal();
    List<Client> clientsList = new ArrayList<>();

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

        while (rs.next()) {
            Firma firmaBD = firmaDao.findById(rs.getInt(7));
            Client client = new Client();
            client.setId(rs.getInt(1));//from w  w  w .  java 2s . c  o  m
            client.setNume(rs.getString(2));
            client.setPrenume(rs.getString(3));
            client.setNrTelefon(rs.getInt(4));
            client.setEmail(rs.getString(5));
            client.setDateExpirare(rs.getTimestamp(6));
            client.setFirma(firmaBD);
            if (rs.getInt(8) == 0) {
                client.setTrimis(false);
            } else {
                client.setTrimis(true);
            }
            clientsList.add(client);
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return clientsList;
}

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

public Connection getCnx(String key) {
    if (cnxMap.containsKey(key)) {
        boolean cl;
        try {/*from www  .ja  va 2  s  .c o  m*/
            cl = cnxMap.get(key).isClosed();
        } catch (SQLException ex) {
            ex.printStackTrace();
            cl = true;
        }
        if (cl) {
            addCnx(createCnx(), key);
        }
        return cnxMap.get(key);
    } else {
        addCnx(createCnx(), key);
        return cnxMap.get(key);
    }
}

From source file:edu.byu.wso2.is.helper.BYUEntityHelper.java

public BYUEntity getBYUEntityFromNetId(String netid) {
    Connection con = null;//from   ww w.  j a  va2s .  c o m
    Statement statement = null;
    ResultSet resultSet = null;
    BYUEntity byuEntity = null;
    try {
        con = ds.getConnection();
        if (log.isDebugEnabled())
            log.debug("connection acquired. creating statement and executing query");
        statement = con.createStatement();
        resultSet = statement.executeQuery("select * from pro.person where net_id = '" + netid + "'");
        if (resultSet.next()) {
            String byu_id = resultSet.getString("byu_id");
            String person_id = resultSet.getString("person_id");
            String net_id = resultSet.getString("net_id");
            String surname = resultSet.getString("surname");
            String rest_of_name = resultSet.getString("rest_of_name");
            String surname_position = resultSet.getString("surname_position");
            String prefix = resultSet.getString("prefix");
            String suffix = resultSet.getString("suffix");
            String sort_name = resultSet.getString("sort_name");
            String preferred_firstname = resultSet.getString("preferred_first_name");
            if (log.isDebugEnabled())
                log.debug("byu_id: " + byu_id + " person_id: " + person_id + " surname: " + surname
                        + " rest_of_name: " + rest_of_name);
            byuEntity = new BYUEntity(net_id, person_id, byu_id, surname, rest_of_name, surname_position,
                    prefix, suffix, sort_name, preferred_firstname);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("resultset is empty");
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
    }
    return byuEntity;
}

From source file:edu.byu.wso2.is.helper.BYUEntityHelper.java

public BYUEntity getBYUEntityFromPersonId(String personid) {
    Connection con = null;/*from  w  w  w. j ava  2 s  .c  om*/
    Statement statement = null;
    ResultSet resultSet = null;
    BYUEntity byuEntity = null;
    try {
        con = ds.getConnection();
        if (log.isDebugEnabled())
            log.debug("connection acquired. creating statement and executing query");
        statement = con.createStatement();
        resultSet = statement.executeQuery("select * from pro.person where person_id = '" + personid + "'");
        if (resultSet.next()) {
            String byu_id = resultSet.getString("byu_id");
            String person_id = resultSet.getString("person_id");
            String net_id = resultSet.getString("net_id");
            String surname = resultSet.getString("surname");
            String rest_of_name = resultSet.getString("rest_of_name");
            String surname_position = resultSet.getString("surname_position");
            String prefix = resultSet.getString("prefix");
            String suffix = resultSet.getString("suffix");
            String sort_name = resultSet.getString("sort_name");
            String preferred_firstname = resultSet.getString("preferred_first_name");
            if (log.isDebugEnabled())
                log.debug("byu_id: " + byu_id + " person_id: " + person_id + " surname: " + surname
                        + " rest_of_name: " + rest_of_name);
            byuEntity = new BYUEntity(net_id, person_id, byu_id, surname, rest_of_name, surname_position,
                    prefix, suffix, sort_name, preferred_firstname);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("resultset is empty");
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
        if (con != null) {
            try {
                con.close();
            } catch (SQLException e) {
                /* ignored */ }
        }
    }
    return byuEntity;
}