List of usage examples for java.sql SQLException printStackTrace
public void printStackTrace()
From source file:com.ouc.cpss.dao.BaseDao.java
/** * //from w w w . j a va 2 s . c om * * @param sql * @param clazz * @return */ public Object get(String sql, Class clazz) { Object obj = null; Connection conn = null; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); obj = qRunner.query(conn, sql, new BeanHandler(clazz)); } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return obj; }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * ??/*from w ww. j a v a 2s .c o m*/ * * @param sql * @param clazz * @return */ public Object get(String sql, Class clazz, Object[] params) { Object obj = null; Connection conn = null; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); obj = qRunner.query(conn, sql, new BeanHandler(clazz), params); } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return obj; }
From source file:com.iucosoft.eavertizare.dao.impl.FirmaDaoImpl.java
@Override public int getMaxId(String tabelaName) { int nr = 0;/*from w w w . j a v a2 s . c o m*/ String query = "SELECT MAX(id) FROM " + tabelaName; try (Connection con = dataSource.getConnection(); Statement stat = con.createStatement(); ResultSet rs = stat.executeQuery(query);) { if (rs.next()) { nr = rs.getInt(1); } } catch (SQLException e) { e.printStackTrace(); } return nr; }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * //www. j av a 2 s .co m * * @return */ public Connection getConnection() { Connection conn = null; String jdbcURL = "jdbc:mysql://localhost:3306/cpss? useUnicode=true&characterEncoding=UTF8"; String jdbcDriver = "com.mysql.jdbc.Driver"; String user = "root"; String password = "527611"; try { //DbUtils DbUtils.loadDriver(jdbcDriver); conn = DriverManager.getConnection(jdbcURL, user, password); } catch (SQLException e) { e.printStackTrace(); } return conn; }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * // www . j a v a 2s.c o m * * @param sql * @param clazz * @return */ public List query(String sql, Class clazz) { List beans = null; Connection conn = null; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); beans = (List) qRunner.query(conn, sql, new BeanListHandler(clazz)); //BeanListHandler?ResultSet???List? //????ResultSet } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return beans; }
From source file:controller.ISLogin.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); try (PrintWriter out = response.getWriter()) { String email = request.getParameter("email"); String password = request.getParameter("password"); JSONObject object = new JSONObject(); if (email != null && password != null) { String sql = "SELECT * FROM user WHERE email = ? AND password = SHA1(?)"; try (PreparedStatement statement = conn.prepareStatement(sql)) { statement.setString(1, email); statement.setString(2, password); ResultSet result = statement.executeQuery(); if (result.next()) { int u_id = result.getInt("u_id"); String uuid = UUID.randomUUID().toString().replaceAll("-", ""); Calendar time = Calendar.getInstance(); time.setTime(new Date()); time.add(Calendar.HOUR, 2); conn.setAutoCommit(false); String delete = "DELETE from token WHERE u_id = ?"; String insert = "INSERT INTO token (access_token, u_id, expiry_date)" + "VALUES (?, ?, ?)"; try (PreparedStatement deleteStatement = conn.prepareStatement(delete); PreparedStatement insertStatement = conn.prepareStatement(insert);) { deleteStatement.setInt(1, u_id); Timestamp timestamp = new Timestamp(time.getTimeInMillis()); insertStatement.setString(1, uuid); insertStatement.setInt(2, u_id); insertStatement.setTimestamp(3, timestamp); deleteStatement.execute(); insertStatement.execute(); object.put("token", uuid); object.put("expiry_date", timestamp.getTime()); conn.commit();/*from ww w. j a v a 2 s .co m*/ } finally { conn.setAutoCommit(true); } } else { object.put("error", "Invalid email or password"); } } catch (SQLException e) { e.printStackTrace(); } } else { object.put("error", "Empty email or password"); } out.println(object.toString()); } }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * sql?,?,,/*from w ww . j av a 2 s . c o m*/ * * @param sql * @return */ public boolean update(String sql, Object[] params) { Connection conn = null; boolean flag = false; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); int i = qRunner.update(conn, sql, params); if (i > 0) { flag = true; } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return flag; }
From source file:com.ouc.cpss.dao.BaseDao.java
/** * ?//from w w w.ja v a2 s . c o m * * @param sql * @param clazz * @return */ public List query(String sql, Class clazz, Object[] params) { List beans = null; Connection conn = null; try { conn = getConnection(); QueryRunner qRunner = new QueryRunner(); beans = (List) qRunner.query(conn, sql, new BeanListHandler(clazz), params); //BeanListHandler?ResultSet???List? //????ResultSet } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(conn); } return beans; }
From source file:hmp.HMPRunRemover.java
private void deleteRpdResultData(ArrayList<Integer> samples) { for (int id : samples) { String sql = "delete from rdp_result_data where sample_id = " + id; int rows = 0; try {/*from w w w . j a v a2 s . c o m*/ rows = conn.createStatement().executeUpdate(sql); } catch (SQLException e) { System.out.println("ERROR deleteRdpResultData:" + sql); e.printStackTrace(); System.exit(0); } System.out.println("deleted " + rows + " from rdp_result_data for sample " + id); } }
From source file:com.asakusafw.testdriver.TestDriverTestToolsBase.java
private void updateTimestamp(String tableName, String timestampColumn, Timestamp timestamp) { LOG.info("{}?{}??????", tableName, timestampColumn); Connection conn = null;//ww w. j av a2 s . co m PreparedStatement stmt = null; try { conn = DbUtils.getConnection(); stmt = conn.prepareStatement( MessageFormat.format("UPDATE {0} SET {1} = ? WHERE {1} IS NULL", tableName, timestampColumn)); stmt.setTimestamp(1, timestamp); int rows = stmt.executeUpdate(); LOG.info("{}?{}?????: {}", new Object[] { tableName, timestampColumn, rows }); if (conn.getAutoCommit() == false) { conn.commit(); } } catch (SQLException e) { e.printStackTrace(); } finally { DbUtils.closeQuietly(stmt); DbUtils.closeQuietly(conn); } }