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:json.ApplicantController.java

@RequestMapping(value = "/getAppliedJobByUserAgain", method = RequestMethod.POST, produces = "application/json")
public @ResponseBody ArrayList<Applicant> getAppliedJobByUserAgain(@RequestBody Applicant applicant) {
    Connection conn = null;//from   ww w.ja  va  2 s . 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;

}

From source file:com.jabyftw.lobstercraft.player.Profile.java

/**
 * Will store the profile on MySQL./*  ww w  .  ja v a 2s  .com*/
 *
 * @param connection MySQL's connection
 * @return true if successfully saved, false if SQLException was thrown
 */
public boolean saveToDatabase(@NotNull final Connection connection) {
    try {
        return onSavingToDatabase(connection);
    } catch (SQLException exception) {
        exception.printStackTrace();
        return false;
    }
}

From source file:io.apiman.gateway.engine.impl.DefaultJdbcComponentTest.java

@Test
public void testDataSource() throws Throwable {
    DefaultJdbcComponent component = new DefaultJdbcComponent();

    BasicDataSource ds = new BasicDataSource();
    ds.setDriverClassName(Driver.class.getName());
    ds.setUsername("sa");
    ds.setPassword("");
    ds.setUrl("jdbc:h2:mem:testDataSource;DB_CLOSE_DELAY=-1");

    try {//  w w  w.  j  av  a  2s .co  m
        IJdbcClient client = component.create(ds);
        doAllTests(client);
    } finally {
        try {
            ds.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}

From source file:classes.SharedClass.java

public void getStatistics() {
    result = db.select("member", new String[] { " count(id) id" }, new String[] { "id" },
            new String[] { "99999" }, "!=", "and");
    try {/*from w  ww.  j  a  v a2  s . co  m*/
        if (result.next()) {
            memberId = result.getInt("id");
        }
    } catch (SQLException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
        ex.printStackTrace();
    }

    //book
    result = db.select("book", new String[] { "count(id)" }, new String[] { "id" }, new String[] { "99999" },
            "!=", "and");
    try {
        if (result.next()) {
            bookId = result.getInt(1);
        }
    } catch (SQLException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
    }

    //operations
    result = db.select("operations", new String[] { "count(id)" }, new String[] { "type" },
            new String[] { "borrowed" }, "=", "and");
    try {
        if (result.next()) {
            operationsId = result.getInt(1);
        }
    } catch (SQLException ex) {
        Logger.getLogger(SharedClass.class.getName()).log(Level.SEVERE, null, ex);
    }
    DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
    dataSet.setValue(memberId, "Percent", "Members");
    dataSet.setValue(bookId, "Percent", "Books");
    dataSet.setValue(operationsId, "Percent", "Borrowe books");
    JFreeChart chart = ChartFactory.createBarChart3D("Statistics", "Fields", "Percent", dataSet,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setBackgroundPaint(Color.yellow);
    chart.getTitle().setPaint(Color.red);
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setRangeGridlinePaint(Color.blue);
    ChartFrame frame = new ChartFrame("Statistics", chart);
    frame.setLocationRelativeTo(null);
    frame.setSize(500, 550);
    frame.setVisible(true);
}

From source file:com.bsg.pcms.provision.contract.ContractController.java

@RequestMapping(value = "deleteAction")
public ModelAndView deleteAction(ContractDTOEx cde) {
    // rv.setExposeModelAttributes(false);
    ModelAndView mav = new ModelAndView(new RedirectView("list.do"));

    // contract_id 
    int result;/* ww  w .ja  v a 2 s .com*/
    try {
        result = contractService.deleteContract(cde);
    } catch (SQLException e) {
        result = 0;
        e.printStackTrace();
    }
    mav.addObject("result", result);

    return mav;
}

From source file:com.handu.open.dubbo.monitor.dao.base.DubboInvokeBaseDAO.java

/**
 * SQL?//w w  w . ja v a  2 s  . c om
 *
 * @param sql SQL?
 * @return boolean
 */
public boolean executeSql(String sql) {
    try {
        return getSqlSession().getConnection().prepareStatement(sql).execute();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return false;
}

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

public BYUEntity getBYUEntityFromNetId(String netid) {
    Connection con = null;/*ww w. j a  va  2 s  .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 + "'");
        byuEntity = getByuEntity(resultSet);
    } 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.helper.BYUEntityHelper.java

public BYUEntity getBYUEntityFromPersonId(String personid) {
    Connection con = null;//from   w w  w  . j a v a 2  s .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 person_id = '" + personid + "'");
        byuEntity = getByuEntity(resultSet);
    } 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:jobimtext.thesaurus.distributional.DatabaseThesaurusDatastructure.java

public List<Order2> getExpansions(String key) {
    try {/*from www .  j  a va 2 s .  c o  m*/
        String sql = "SELECT word1, word2,count FROM " + tableOrder2 + " WHERE word1 = ? ORDER BY count desc";
        PreparedStatement ps = getDatabaseConnection().getConnection().prepareStatement(sql);
        ps.setString(1, key);
        return fillExpansions(ps);
    } catch (SQLException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

protected static DBConnection getNewDBConnection() {
    Pair<String, String> namePair = null;
    Pair<String, String> usrNmPwd = null;
    final SpecifyDBConverter converter = new SpecifyDBConverter();
    try {//  w  w w  .j  a v a 2s .com

        if (converter.selectedDBsToConvert(true)) {
            namePair = converter.chooseTable("Choose", "Select a Specify 6 Database", false);
            usrNmPwd = converter.getItUsrPwd();
        }

    } catch (SQLException ex) {
        ex.printStackTrace();
        JOptionPane.showConfirmDialog(null, "The Sp5Forms was unable to login.", "Error",
                JOptionPane.CLOSED_OPTION);
    }

    if (namePair != null) {
        DatabaseDriverInfo driverInfo = DatabaseDriverInfo.getDriver("MySQL");
        String oldConnStr = driverInfo.getConnectionStr(DatabaseDriverInfo.ConnectionType.Open,
                converter.getHostName(), namePair.second, usrNmPwd.first, usrNmPwd.second,
                driverInfo.getName());

        DBConnection dbConn = DBConnection.createInstance(driverInfo.getDriverClassName(),
                driverInfo.getDialectClassName(), namePair.second, oldConnStr, usrNmPwd.first, usrNmPwd.second);

        Connection connection = dbConn.createConnection();
        if (connection != null) {
            try {
                connection.close();
                return dbConn;

            } catch (SQLException ex) {
                // do nothing
            }
        }
    }
    return null;
}