| Author |
problem in adding field to database
|
zohreh talebi
Ranch Hand
Joined: Sep 01, 2006
Posts: 41
|
|
Dears, When the user try to register the site , his/her information should write in database.My problem is,it gives me nullPointerException .Before fields add to database , it prints all content true but i don't know why this exception eccure: javax.servlet.ServletException: #{dbBean.addUser}: javax.faces.el.EvaluationException: java.lang.NullPointerException javax.faces.webapp.FacesServlet.service(FacesServlet.java:209) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368) -------------------------------------------------------------------------- register.jsp <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Home Page</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="main"> <%@ include file="header.html" %> <div id="left"> <div class="left_text"> <div class="title_left"> <font color="brown"> </font> </div> <p> <f:view> <h:form id="form1" > First Name : <h:inputText id ="fullName" value="#{dbBean.fullName}"/><BR> email : <h:inputText id ="email" value="#{dbBean.email}"/><BR> password : <h:inputSecret id ="password" value="#{dbBean.password}"/><BR> job : <h:inputText id ="job" value="#{dbBean.job}"/><BR> <h:commandButton value="Register" action="#{dbBean.addUser}"/> </h:form> </f:view> </p> </div> </div> <jsp:include flush="true" page="links.jsp"/> <div id="bottom"> <div style="background-color:#333333;"> <div class="bottom"> <div class="title"> <font color="brown"> Lorem ipsum </font> </div> <div class="text_bottom"> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam at libero. Suspendisse non risus a diam convallis <a href="#">lobortis</a>. </div> </div> </div> </div> <%@ include file="footer.html" %> </div> </body> </html> ------------------------------------------------------------------------ addUser() public String addUser() { UserBean bean = new UserBean(); ExternalContext context = FacesContext.getCurrentInstance().getExternalContext(); HttpServletRequest request = (HttpServletRequest)context.getRequest(); String fullName = request.getParameter("form1:fullName"); bean.setFullName(fullName); String email = request.getParameter("form1:email"); bean.setEmail(email); String password = request.getParameter("form1:password"); bean.setPassword(password); String job = request.getParameter("form1:job"); bean.setJob(job); try { Connection Conn = DBManager.getConnection(); Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE ,ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery("select * from user"); rs.moveToInsertRow(); rs.updateString(1, bean.getFullName()); System.out.println("name"+ bean.getFullName()); rs.updateString(2, bean.getEmail()); rs.updateString(3, bean.getPassword()); rs.updateString(4,bean.getJob()); rs.insertRow(); rs.first(); } catch (SQLException ex) { ex.printStackTrace(); return "failed"; } return "sucsess" ; } Thanks in advance Zohreh
|
 |
 |
|
|
subject: problem in adding field to database
|
|
|