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.its.web.orm.Database.java

@PostConstruct
public void init() {
    try {//from  w  w  w .  j  ava2s  . c o m
        connectionSource = new JdbcConnectionSource(databaseUrl, login, password);

        //Products
        productDao = DaoManager.createDao(connectionSource, Product.class);
        if (!productDao.isTableExists()) {
            TableUtils.createTable(connectionSource, Product.class);
        }

        //Licenses
        licenseDao = DaoManager.createDao(connectionSource, License.class);
        if (!licenseDao.isTableExists()) {
            TableUtils.createTable(connectionSource, License.class);
        }

        //WebUser
        webUserDao = DaoManager.createDao(connectionSource, WebUser.class);
        if (!webUserDao.isTableExists()) {
            TableUtils.createTable(connectionSource, WebUser.class);
        }

        //licenseTypeDao
        licenseTypeDao = DaoManager.createDao(connectionSource, LicenseType.class);
        if (!licenseTypeDao.isTableExists()) {
            TableUtils.createTable(connectionSource, LicenseType.class);
        }

    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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

@Override
public List<Firma> findAll() {
    String query = "select * from firme";
    List<Firma> firmaList = new ArrayList<>();

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

        while (rs.next()) {
            Configuratii configuratie = configuratiiDao.findById(rs.getInt(7));
            Firma firma = new Firma();
            firma.setId(rs.getInt(1));//from   w  w w.java2 s .com
            firma.setNumeFirma(rs.getString(2));
            firma.setAdresaFirma(rs.getString(3));
            firma.setDescriereFirma(rs.getString(4));
            firma.setTabelaClientiLocal(rs.getString(5));
            firma.setMesajPentruClienti(rs.getString(6));
            firma.setConfiguratii(configuratie);
            firmaList.add(firma);
        }
    } catch (SQLException e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(new JFrame(), e, "Error", JOptionPane.ERROR_MESSAGE);
        System.exit(-1);
    }
    return firmaList;
}

From source file:hmp.HMPRunRemover.java

private void deleteSampleData(ArrayList<Integer> samples) throws SQLException {
    for (int id : samples) {
        String sql = "delete from sample_data where sample_id = " + id;
        int rows = 0;
        try {/*from   w w w  .ja  v  a 2  s  .  com*/
            rows = conn.createStatement().executeUpdate(sql);
        } catch (SQLException sQLException) {
            System.out.println("ERROR deleteSampleData:" + sql);
            sQLException.printStackTrace();
            System.exit(0);
        }
        System.out.println("deleted " + rows + " from sample_data for sample " + id);
    }
}

From source file:br.com.mysqlmonitor.monitor.Monitor.java

private List<Tabela> carregarTabelas(Servidor servidor) {
    List<Tabela> listaTabela = new ArrayList<Tabela>();
    try {/*from  w w  w  .  j  av a  2 s. c o  m*/
        StringBuilder query = new StringBuilder("SHOW TABLES");
        Connection con = conexaoJDBC.iniciarConexao(servidor);
        Statement stm = con.createStatement();
        ResultSet rs = stm.executeQuery(query.toString());
        while (rs.next()) {
            Tabela tabela = new Tabela(
                    rs.getString("Tables_in_" + servidor.getGrupoServidor().getBancoDados()));
            tabela.setCampos(carregarCamposTabela(servidor,
                    new Tabela(rs.getString("Tables_in_" + servidor.getGrupoServidor().getBancoDados()))));
            listaTabela.add(tabela);
        }
        stm.close();
        con.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return listaTabela;
}

From source file:com.jaspersoft.jasperserver.war.CSVServlet.java

private void printQuery(String sqlQuery, Connection conn, PrintWriter out) {
    log.info("drill-through SQL = " + sqlQuery);
    try {//from  w ww.j av  a2s. co m
        Statement s = conn.createStatement();
        ResultSet rs = s.executeQuery(sqlQuery);
        printCSV(rs, out);
        rs.close();
    } catch (Exception e) {
        e.printStackTrace();
        log.error(e);
    } finally {
        try {
            conn.close();
        } catch (SQLException sqle) {
            sqle.printStackTrace();
            log.error(sqle);
        }
    }
}

From source file:edu.ku.brc.specify.datamodel.DataModelObjBase.java

/**
 * Deletes the data object./*from w w w  .j  av a2  s  .  c  om*/
 * @param doShowError whether to show the an error dialog
 * @return true is ok, false if not
 */
public static boolean delete(final int id, final int tableId, final boolean doShowError) {
    errMsg = null;

    DBTableInfo ti = DBTableIdMgr.getInstance().getInfoById(tableId);
    Connection connection = DBConnection.getInstance().createConnection();
    Statement stmt = null;
    try {
        stmt = connection.createStatement();
        int numRecs = stmt
                .executeUpdate("DELETE FROM " + ti.getName() + " WHERE " + ti.getIdColumnName() + " = " + id);
        if (numRecs != 1) {
            // TODO need error message
            return false;
        }

    } catch (SQLException ex) {
        edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
        ex.printStackTrace();
        errMsg = ex.toString();

        try {
            connection.rollback();

        } catch (SQLException ex2) {
            edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex2);
            ex.printStackTrace();
        }
        return false;

    } finally {
        try {
            if (stmt != null) {
                stmt.close();
            }
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            edu.ku.brc.af.core.UsageTracker.incrSQLUsageCount();
            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(DataModelObjBase.class, ex);
            ex.printStackTrace();
        }
    }
    return true;
}

From source file:fitmon.WorkoutData.java

public ArrayList<ArrayList> getTotalCaloriesBurned(int userId) throws SQLException {
    PreparedStatement st = null;//from   www  .j  a v  a2  s  . com
    Connection conn = null;
    ArrayList<ArrayList> calBurnedList = new ArrayList<ArrayList>();
    try {
        String query = "select date,sum(calories) from Workout where userId=" + userId
                + " group by date limit 5";
        Class.forName("com.mysql.jdbc.Driver");
        conn = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/fitmon", "root",
                "april-23");
        st = conn.prepareStatement(query);
        conn.setAutoCommit(false);

        ArrayList calBurned = new ArrayList();
        ResultSet rs = st.executeQuery(query);
        while (rs.next()) {
            calBurned = new ArrayList();
            calBurned.add(rs.getString("date"));
            calBurned.add(rs.getDouble("sum(calories)"));
            calBurnedList.add(calBurned);
        }
        st.close();
        conn.close();

    } catch (ClassNotFoundException ce) {
        ce.printStackTrace();
    } catch (SQLException se) {
        se.printStackTrace();
    } catch (Exception e) {
        //Handle errors for Class.forName
        e.printStackTrace();
    } finally {

        if (st != null) {
            st.close();
        }

        if (conn != null) {
            conn.close();
        }

    }

    return calBurnedList;
}

From source file:hmp.HMPRunRemover.java

private void deleteSampleCounts(ArrayList<Integer> samples) {
    for (int id : samples) {
        String sql = "delete from sample_count where sample_id = " + id;
        int rows = 0;
        try {/*from w  ww . ja va2  s  .  c  o m*/
            rows = conn.createStatement().executeUpdate(sql);
        } catch (SQLException sQLException) {
            System.out.println("ERROR deleteSampleCounts:" + sql);
            sQLException.printStackTrace();
            System.exit(0);
        }
        System.out.println("deleted " + rows + " from sample_count for sample " + id);
    }
}

From source file:br.com.mysqlmonitor.monitor.Monitor.java

private List<Campo> carregarCamposTabela(Servidor servidor, Tabela tabela) {
    List<Campo> listaCampo = new ArrayList<Campo>();
    try {/*from w  ww . ja va  2 s.c o m*/
        StringBuilder query = new StringBuilder("DESC ").append(tabela.getNomeTabela());
        Connection con = conexaoJDBC.iniciarConexao(servidor);
        Statement stm = con.createStatement();
        ResultSet rs = stm.executeQuery(query.toString());
        while (rs.next()) {
            Campo campo = new Campo();
            campo.setNome(rs.getString("Field"));
            campo.setTipo(rs.getString("Type"));
            campo.setPermiteNull(rs.getString("Null"));
            campo.setKey(rs.getString("Key"));
            campo.setValorDefault(rs.getString("Default"));
            campo.setExtra(rs.getString("Extra"));
            listaCampo.add(campo);
        }
        stm.close();
        con.close();
    } catch (SQLException ex) {
        ex.printStackTrace();
    }
    return listaCampo;
}

From source file:json.ApplicantController.java

@RequestMapping(value = "/getAppliedJobByUser", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody ArrayList<Applicant> getAppliedJobByUser(@RequestBody Applicant applicant) {
    Connection conn = null;/*from w  w  w .jav  a  2s  .c o  m*/
    PreparedStatement stmt = null;
    ResultSet rs = null;

    ArrayList<Applicant> appliedJobList = new ArrayList<Applicant>();
    String query = "SELECT a.username, j.postingTitle, j.businessUnit, j.location, j.createdBy, j.createdOn, j.statusCode, j.employmentType, j.shift, j.description, j.requirement, j.validity, a.jobIDApplied, appID, a.dateApplied, status FROM application a INNER JOIN job j on j.jobID = a.jobIDApplied where a.username = \""
            + applicant.getUsername() + "\"";
    try {
        //Set up connection with database
        conn = ConnectionManager.getConnection();
        stmt = conn.prepareStatement(query);
        //stmt.setString(1, username);

        //Execute sql satatement to obtain account from database
        rs = stmt.executeQuery();
        //Execute sql satatement to obtain jobs from database
        // rs = stmt.executeQuery("SELECT a.username, j.postingTitle, j.businessUnit, j.location, j.createdBy, j.CreatedOn, J.statusCode, j.employmentType, j.shift, j.description, j.requirement, j.validity,a.jobIDApplied, appID, a.dateApplied, status FROM application a INNER JOIN job j on j.jobID = a.jobIDApplied where a.username = + '" + username  + "' ORDER BY appID desc ");

        while (rs != null && rs.next()) {
            String name = rs.getString(1);
            String postingTitle = rs.getString(2);
            String businessUnit = rs.getString(3);
            String location = rs.getString(4);
            String createdBy = rs.getString(5);
            String createdOn = rs.getString(6);
            String employmentType = rs.getString(8);
            String shift = rs.getString(9);
            String description = rs.getString(10);
            String requirement = rs.getString(11);
            String validity = rs.getString(12);
            int jobID = rs.getInt(13);
            int appID = rs.getInt(14);
            String dateApplied = rs.getString(15);
            String status = rs.getString(16);

            Jobs job = new Jobs(jobID, businessUnit, postingTitle, createdBy, createdOn, location,
                    employmentType, shift, description, requirement, validity);
            Applicant a = new Applicant(appID, jobID, name, dateApplied, status, jobID, businessUnit,
                    postingTitle, createdBy, createdOn, location, employmentType, shift, description,
                    requirement, validity);
            //                /int appID, int jobIDApplied, String username, String dateApplied, String status, 
            appliedJobList.add(a);
            System.out.println(requirement);

        }
    } catch (SQLException ex) {
        ex.printStackTrace();
    } finally {
        ConnectionManager.close(conn, stmt, rs);
    }
    System.out.println(appliedJobList.size());
    return appliedJobList;

}