Guest User

register

a guest
Mar 19th, 2018
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
  2. {
  3. PrintWriter out = res.getWriter();
  4. res.setContentType("text/html");
  5.  
  6. try
  7. {
  8. res.setContentType("text/html");
  9.  
  10. Class.forName("oracle.jdbc.driver.OracleDriver");
  11.  
  12. Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:XE" , "system" , "connect" );
  13.  
  14. String name = req.getParameter("name");
  15. String userName = req.getParameter("userName");
  16. String password = req.getParameter("password");
  17. String email = req.getParameter("email");
  18. String mobile = req.getParameter("mobile");
  19.  
  20. checkUserValid(con,userName);
  21.  
  22. PreparedStatement ps = con.prepareStatement("insert into table values( ?,?,?,? )");
  23. ps.setString(1, userName);
  24. ps.setString(2, password);
  25. ps.setString(3, email);
  26. ps.setString(4, mobile);
  27.  
  28. int x = ps.executeUpdate();
  29.  
  30. if(x>=1) {
  31. System.out.println("registration successful");
  32. } else {
  33. System.out.println("couldnot register");
  34. }
  35.  
  36. }
  37. catch(Exception e) {
  38. e.printStackTrace();
  39. }
  40. }
  41.  
  42. private boolean checkUserValid(Connection con,String userName) throws SQLException
  43. {
  44. Statement st = con.createStatement();
  45. ResultSet rs = st.executeQuery("select * from table where userName = "+userName);
  46.  
  47. try
  48. {
  49. if(rs.next())
  50. {
  51. return false;
  52. }
  53. }
  54. catch (SQLException e)
  55. {
  56. e.printStackTrace();
  57. }
  58. return true;
  59. }
Add Comment
Please, Sign In to add comment