A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Frameworks
»
Struts
Author
new user exists or not
Aditi agarwal
Ranch Hand
Joined: Feb 23, 2011
Posts: 225
posted
Mar 15, 2011 11:28:31
0
I want to add a new user & check that weather user exists if yes then failure else success
My action class is:-
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { NewuserloginForm newuserloginForm = (NewuserloginForm) form;// TODO Auto-generated method stub database db = new database(); Connection conn =db.getConnection(); Statement s=null; ResultSet rs=null; int a1 = 0; try { s=conn.createStatement(); rs=s.executeQuery("select loginname from ams_login;"); while(rs.next()) { if(rs.next()) { System.out.println("user already exists"); } else { PreparedStatement st = conn.prepareStatement("INSERT INTO ams_login(loginname,password,logintype,accesslevel) VALUES (?, ?, ?, ?)"); st.setString(1, newuserloginForm.getLoginname()); st.setString(2, newuserloginForm.getPassword()); st.setString(3, newuserloginForm.getLogintype()); st.setString(4, newuserloginForm.getAccesslevel()); a1=st.executeUpdate(); System.out.println("Result of prepared satement: " + a1); if (a1 == 1) { return mapping.findForward("success"); } } } } catch (SQLException e) { // TODO Auto-generated catch block request.setAttribute("error", "server"); e.printStackTrace(); mapping.findForward("failure"); } finally { // Always close the database connection. try { if (conn != null) conn.close(); } catch (SQLException ignored){ System.out.println(ignored); } } return mapping.findForward("failure"); } }
I agree. Here's the link:
http://aspose.com/file-tools
subject: new user exists or not
Similar Threads
password hashingsalting in struts
change password
session problem
problem in my action class
update query
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter