Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Struts
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Struts
new user exists or not
Aditi agarwal
Ranch Hand
Posts: 225
posted 13 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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"); } }
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
problem in my action class
change password
update query
password hashingsalting in struts
session problem
More...