• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

problem in adding field to database

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
Enterprise-grade Excel API for Java
https://products.aspose.com/cells/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!