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:fr.calamus.common.db.core.DbPool.java

public String findAndBindUsableCnx() {
    try {/*from ww w.j av a  2  s .  c o  m*/
        String usable = null;
        for (String key : cnxKeys) {
            if (!busyCnxKeys.contains(key)) {
                cnx = getCnx(key);
                usable = key;
            }
        }
        if (usable == null) {
            usable = addCnx(createCnx());
        }
        cnx = getCnx(usable);
        if (getCnx(usable) == null || getCnx(usable).isClosed()) {
            usable = addCnx(createCnx(), usable);
        }

        return usable;
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return null;
}

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

public String openInTransactionMode() {
    try {//  w  ww . j av a  2 s.c om
        Connection cnx = null;
        String usable = null;
        for (String key : cnxKeys) {
            if (!busyCnxKeys.contains(key)) {
                cnx = getCnx(key);
                usable = key;
            }
        }
        if (usable == null) {
            usable = addCnx(createCnx());
        }
        if (getCnx(usable) == null || getCnx(usable).isClosed()) {
            usable = addCnx(createCnx(), usable);
        }
        transactionCnxKeys.add(usable);
        getStatement(usable);
        setBusy(usable);
        return usable;
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return null;
}

From source file:com.abixen.platform.module.chart.service.impl.AbstractDatabaseService.java

public List<String> getTables(Connection connection) {

    final int objectTypeIndex = 4;
    final int objectNameIndex = 3;

    List<String> tables = new ArrayList<>();

    try {// www  . j  av a  2  s .  c o  m
        ResultSet rs = getTablesAsResultSet(connection);

        while (rs.next()) {
            if ("TABLE".equals(rs.getString(objectTypeIndex)) || "VIEW".equals(rs.getString(objectTypeIndex))) {
                if (isAllowedTable(rs.getString(objectNameIndex))) {
                    tables.add(rs.getString(objectNameIndex));
                }
            }
        }

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

From source file:com.abixen.platform.module.chart.service.impl.AbstractDatabaseService.java

private List<Map<String, DataSourceValueWeb>> getData(Connection connection,
        DatabaseDataSource databaseDataSource, Set<String> chartColumnsSet) {
    ResultSet rs;// ww w . j a v a2 s  .  com
    List<Map<String, DataSourceValueWeb>> data = new ArrayList<>();
    try {
        Statement statement = connection.createStatement();
        rs = statement.executeQuery(buildQueryForChartData(databaseDataSource, chartColumnsSet));

        if (rs != null) {
            while (rs.next()) {
                final ResultSet row = rs;
                Map<String, DataSourceValueWeb> rowMap = new HashMap<>();
                chartColumnsSet.forEach(chartColumnsSetElement -> {
                    rowMap.put(chartColumnsSetElement, getDataFromColumn(row, chartColumnsSetElement));
                });
                data.add(rowMap);
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
        throw new DataParsingException("Error when parsing data from db. " + e.getMessage());
    }
    return data;
}

From source file:org.psystems.dicom.browser.server.stat.StatClientRequestsChartServlet.java

/**
 * Returns a sample dataset./*from w ww.  ja  v  a 2  s  .  c o  m*/
 * 
 * @return The dataset.
 */
private CategoryDataset createDataset() {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    Calendar calendarEnd = Calendar.getInstance();
    int tzoffset = calendarEnd.getTimeZone().getOffset(calendarEnd.getTimeInMillis());

    long time = calendarEnd.getTimeInMillis();
    time = time - (time % (60 * 60 * 24 * 1000)) - tzoffset;
    calendarEnd.setTimeInMillis(time);

    try {
        Connection connection = Util.getConnection("main", getServletContext());

        Calendar calendarBegin = (Calendar) calendarEnd.clone();
        calendarBegin.add(Calendar.DAY_OF_MONTH, -7);

        getMetrics(connection, " ?", "CLIENT_CONNECTIONS",
                calendarBegin.getTimeInMillis(), calendarEnd.getTimeInMillis(), dataset);

    } catch (SQLException e) {
        logger.error(e);
        e.printStackTrace();
    }
    return dataset;
}

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

private void runNetezzaTest(String tableName, String[] argv, ColumnGenerator... extraCols) throws IOException {
    SqoopOptions options = new SqoopOptions(NetezzaTestUtils.getNZConnectString(), getTableName());
    options.setUsername(NetezzaTestUtils.getNZUser());
    options.setPassword(NetezzaTestUtils.getNZPassword());

    LOG.info("Running export with argv : " + Arrays.toString(argv));
    manager = new DirectNetezzaManager(options);

    try {/*from w ww.j a  va 2  s.c o m*/
        createTable(extraCols);
        LOG.info("Created table " + tableName);
        createExportFile(extraCols);
        // run the export and verify that the results are good.
        runExport(argv);
        verifyExport(3, conn);
        if (extraCols.length > 0) {
            assertColMinAndMax(forIdx(0), extraCols[0]);
        }
    } catch (SQLException sqlE) {
        LOG.error("Encountered SQL Exception: " + sqlE);
        sqlE.printStackTrace();
        fail("SQLException when accessing target table. " + sqlE);
    }
}

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

public BYUEntity getBYUEntityFromConsumerKey(String consumerKey) {
    Connection con = null;/*from  ww  w .  j  a  v a 2  s  .  co  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");

        if (log.isDebugEnabled())
            log.debug("consumer key: " + consumerKey);

        statement = con.createStatement();
        String query = "select * from pro.person p, iam.credential c where p.byu_id = c.byu_id "
                + "and c.credential_type = 'WSO2_CLIENT_ID' and c.credential_id = '" + consumerKey + "'";
        if (log.isDebugEnabled())
            log.debug("query: " + query);
        resultSet = statement.executeQuery(query);
        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:com.mkmeier.quickerbooks.ProcessSquare.java

private List<QbAccount> getList(String sql) {
    List<QbAccount> accounts = new ArrayList<QbAccount>();

    Connection conn = null;//from  www.  j av  a2 s.  co m
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        conn = DatabaseConnection.getDatabaseConnection(host, db, user, password);

        stmt = conn.prepareStatement(sql);
        rs = stmt.executeQuery();

        while (rs.next()) {
            QbAccount acct = new QbAccount();
            acct.setName(rs.getString("name"));
            acct.setAcctType(rs.getString("acct_type"));
            acct.setAcctNum(rs.getInt("acct_num"));

            accounts.add(acct);
        }

    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (rs != null) {
                rs.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        try {
            if (stmt != null) {
                stmt.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }

        try {
            if (conn != null) {
                conn.close();
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    return accounts;
}

From source file:fr.crnan.videso3d.ihm.PLNSPanel.java

private JToolBar createToolbar() {
    JToolBar toolbar = new JToolBar();

    JButton newGraph = new JButton("Nouveau");
    newGraph.addActionListener(new ActionListener() {

        @Override/*from   www .j a  va  2s  .co  m*/
        public void actionPerformed(ActionEvent e) {
            PLNSChartCreateUI chartCreator = new PLNSChartCreateUI(PLNSPanel.this);
            JFreeChart chart = null;
            try {
                if (chartCreator.showDialog(PLNSPanel.this)) {
                    switch (chartCreator.getChartType()) {
                    case 0://XY
                        JDBCXYDataset dataset = new JDBCXYDataset(plnsAnalyzer.getConnection());
                        dataset.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createXYAreaChart(chartCreator.getChartTitle(),
                                chartCreator.getAbscissesTitle(), chartCreator.getOrdonneesTitle(), dataset,
                                PlotOrientation.VERTICAL, false, true, false);
                        break;
                    case 1://Pie
                        JDBCPieDataset dataset1 = new JDBCPieDataset(plnsAnalyzer.getConnection());
                        dataset1.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createPieChart3D(chartCreator.getChartTitle(), dataset1, false,
                                true, false);
                        break;
                    case 2://Category
                        JDBCCategoryDataset dataset2 = new JDBCCategoryDataset(plnsAnalyzer.getConnection());
                        dataset2.executeQuery(chartCreator.getRequest());
                        chart = ChartFactory.createBarChart(chartCreator.getChartTitle(),
                                chartCreator.getAbscissesTitle(), chartCreator.getOrdonneesTitle(), dataset2,
                                PlotOrientation.VERTICAL, false, true, false);
                        break;
                    default:
                        break;
                    }
                }
            } catch (SQLException e1) {
                e1.printStackTrace();
                JOptionPane.showMessageDialog(PLNSPanel.this,
                        "<html>L'excution de la requte a chou :<br />" + e1 + "</html>",
                        "Impossible de crer le graphique", JOptionPane.ERROR_MESSAGE);
            }
            if (chart != null)
                addChart(chart);

        }
    });

    toolbar.add(newGraph);

    JButton retile = new JButton("Rarranger");
    retile.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            desktop.tile(true);
        }
    });
    toolbar.add(retile);

    return toolbar;
}

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

@Override
public void saveLocal(Firma firma, List<Client> clientsList) {

    String query = "INSERT INTO " + firma.getTabelaClientiLocal() + " VALUES(?, ?, ?, ?, ?, ?, ?, ?)";
    Connection con = null;/*from   w w  w .  j a  va  2  s  .  co m*/
    PreparedStatement ps = null;
    try {
        con = dataSource.getConnection();
        ps = con.prepareStatement(query);
        // Set auto-commit to false
        con.setAutoCommit(false);

        for (Client client : clientsList) {
            ps.setInt(1, client.getId());
            ps.setString(2, client.getNume());
            ps.setString(3, client.getPrenume());
            ps.setInt(4, client.getNrTelefon());
            ps.setString(5, client.getEmail());
            ps.setTimestamp(6, (new java.sql.Timestamp(client.getDateExpirare().getTime())));
            ps.setInt(7, firma.getId());
            ps.setInt(8, 0);

            ps.addBatch();
        }

        // Create an int[] to hold returned values
        int[] count = ps.executeBatch();
        //Explicitly commit statements to apply changes
        con.commit();

    } catch (SQLException e) {
        e.printStackTrace();
        try {
            con.rollback();
        } catch (SQLException ex) {
            Logger.getLogger(ClientsDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    } finally {
        try {
            ps.close();
            con.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}