Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
- {
- PrintWriter out = res.getWriter();
- res.setContentType("text/html");
- try
- {
- res.setContentType("text/html");
- Class.forName("oracle.jdbc.driver.OracleDriver");
- Connection con = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:XE" , "system" , "connect" );
- String name = req.getParameter("name");
- String userName = req.getParameter("userName");
- String password = req.getParameter("password");
- String email = req.getParameter("email");
- String mobile = req.getParameter("mobile");
- checkUserValid(con,userName);
- PreparedStatement ps = con.prepareStatement("insert into table values( ?,?,?,?,? )");
- ps.setString(1, userName);
- ps.setString(2, name);
- ps.setString(3, password);
- ps.setString(4, email);
- ps.setString(5, mobile);
- int x = ps.executeUpdate();
- if(x>=1) {
- System.out.println("registration successful");
- } else {
- System.out.println("couldnot register");
- }
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- private boolean checkUserValid(Connection con,String userName) throws SQLException
- {
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery("select * from table where userName = "+userName);
- try
- {
- if(rs.next())
- {
- return false;
- }
- }
- catch (SQLException e)
- {
- e.printStackTrace();
- }
- return true;
- }
Add Comment
Please, Sign In to add comment