set from Form Bean return null pointer value error
This is my action .java
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package basepackage.struts.action;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import basepackage.struts.form.PreeditForm;
/**
* MyEclipse Struts
* Creation date: 07-24-2007
*
* XDoclet definition:
* @struts.action validate="true"
* @struts.action-forward name="preedit" path="/form/edit.jsp"
*/
publicclass PreeditActionextends Action{
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
PreeditForm preeditForm = (PreeditForm) form;
DataSource dataSource;
Connection myConn =null;
try{
dataSource = getDataSource(request,"SQLDB");
myConn = dataSource.getConnection();
if (!myConn.isClosed())
System.out.println("Successfully connected to "
+"MySQL server using TCP/IP...");
}
catch (SQLException e)
{
System.err.println("Exception1: " + e.getMessage());
}
Statement stmt =null;
ResultSet rs =null;
String userid="";
String userdb ="";
String passdb ="";
try{
stmt = myConn.createStatement();
String sqlqry ="select * from test.login where id='1'";
rs = stmt.executeQuery(sqlqry);
if (rs.next())
{
userid = rs.getString("id");
userdb = rs.getString("username");
passdb = rs.getString("password");
}
System.out.println(userid);
System.out.println(userdb);
System.out.println(passdb);
preeditForm.setID(userid);
preeditForm.setUsername(userdb);
editForm.setPassword(passdb);
}catch (SQLException e){
System.err.println("Exception2: " + e.getMessage());
}finally{
try{
rs.close();
stmt.close();
myConn.close();
}catch (SQLException e){
System.err.println("Exception3: " + e.getMessage());
}
}
return mapping.findForward("preedit");
}
}
and this is my Form Bean
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package basepackage.struts.form;
import org.apache.struts.action.ActionForm;
/**
* MyEclipse Struts
* Creation date: 07-24-2007
*
* XDoclet definition:
* @struts.form name="editForm"
*/
publicclass PreeditFormextends ActionForm{
/*
* Generated fields
*/
/** password property */
private String password;
/** username property */
private String username;
private String ID;
/*
* Generated Methods
*/
/**
* Returns the password.
* @return String
*/
public String getPassword(){
return password;
}
/**
* Set the password.
* @param password The password to set
*/
publicvoid setPassword(String password){
this.password = password;
}
/**
* Returns the username.
* @return String
*/
public String getUsername(){
return username;
}
/**
* Set the username.
* @param username The username to set
*/
publicvoid setUsername(String username){
this.username = username;
}
public String getID(){
return ID;
}
publicvoid setID(String ID){
this.ID = ID;
}
}
and this is the error
type Exception report
message
description The server encountered an internal error () that prevented it from fulfillingthis request.
exception
javax.servlet.ServletException
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.NullPointerException
basepackage.struts.action.PreeditAction.execute(PreeditAction.java:89)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
After I examine, i found out that the problem is in these line
preeditForm.setID(userid);
preeditForm.setUsername(userdb);
editForm.setPassword(passdb);
Can someone help me ?
Thank you before

