public boolean findUser(String un, String pwd) { Connection con = null; try { con = DBConnectionFactory.getConnection(); String sql = "select count(uname) from user_details" + " where uname='" + un + "' and pass='******'"; PreparedStatement st = con.prepareStatement(sql); ResultSet rs = st.executeQuery(); rs.next(); int count = rs.getInt(1); return (count == 1); } catch (SQLException e) { e.printStackTrace(); } finally { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } // finally return false; }
@Override public User getUserDetails(String uname) { Connection con = null; try { con = DBConnectionFactory.getConnection(); Statement st = con.createStatement(); String sql = "select fname, lname, email, mobile, usertype " + "from user_details " + "where uname='" + uname + "'"; ResultSet rs = st.executeQuery(sql); if (rs.next()) { User u = new User(); u.setUname(uname); u.setFname(rs.getString(1)); u.setLname(rs.getString(2)); u.setEmail(rs.getString(3)); u.setMobile(rs.getString(4)); u.setUsertype(rs.getString(5)); return u; } } catch (SQLException e) { e.printStackTrace(); } finally { try { con.close(); } catch (SQLException e) { e.printStackTrace(); } } return null; }
@WdprMethodLog private static void loadCustomerDetails(Customer customer) throws ClassNotFoundException, IOException, SQLException, Exception { Connection conn = null; PreparedStatement statement = null; ResultSet rs = null; try { logging.debug(" Start loadCustomer"); DBConnectionFactory dbFactory = DBConnectionFactory.getInstance(); conn = dbFactory.getConnection(); long queryStartTime = System.nanoTime(); queryStartTime = System.nanoTime(); String sql = buildInsertQuery(customer); statement = conn.prepareStatement(sql); statement = populateValues(customer, statement); rs = statement.executeQuery(); long queryEndTime = System.nanoTime(); logging.info( "Total_time_PS_loadCustomer : taken to execute loadCustomer query:=" + TimeUnit.MILLISECONDS.convert( (queryEndTime - queryStartTime), TimeUnit.NANOSECONDS)); logging.debug(" End time of loadCustomer Query : "); } catch (Exception ex) { logging.error(ex.getLocalizedMessage()); throw ex; } finally { if (rs != null) rs.close(); if (statement != null) statement.close(); if (conn != null) conn.close(); } }
public DerbyDAOImpl() throws ServiceLocatorException, SQLException { connection = DBConnectionFactory.getConnection(); logger.info("Got connection"); }