我正在为我的 Web 应用程序创建一个注册表单,当我尝试访问注册新用户时出现以下错误:
java.lang.VerifyError: (class: eBooks/Data/UserDB, method: <init> signature: ()V) Constructor must call super() or this() java.lang.VerifyError: (class: eBooks/Data/UserDB, method: <init> signature: ()V) Constructor must call super() or this()
at eBooks.controller.RegisterUserServlet.doPost(RegisterUserServlet.java:62)
这是 UserDB 类:
package eBooks.Data;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import eBooks.business.User;
import eBooks.util.DBUtil;
public class UserDB {
public static int insert(User user)
{
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
String query =
"INSERT INTO User (fName, lName, email_address, password, dataOfBirth, phone,"
+ " address, city, state, country, zipcode, accountType)"
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?)";
try
{
ps = connection.prepareStatement(query);
ps.setString(1, user.getfName());
ps.setString(2, user.getlName());
ps.setString(3, user.getEmailAddress());
ps.setString(4, user.getPassword());
ps.setString(5, user.getDateOfBirth());
ps.setString(5, user.getPhone());
ps.setString(6, user.getAddress());
ps.setString(7, user.getCity());
ps.setString(8, user.getCountry());
ps.setString(9, user.getState());
ps.setString(10, user.getZipcode());
//ps.setString(11, user.getAccountType()); -- Ask Jassin
return ps.executeUpdate();
}
catch(SQLException e)
{
e.printStackTrace();
return 0;
}
finally
{
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
public static int update(User user)
{
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
String query = "UPDATE User SET"
+ "fName = ?"
+ "lName = ?"
+ "password = ?"
+ "dateOfBirth = ?"
+ "phone = ?"
+ "address = ?"
+ "city = ?"
+ "state_or_Region = ?"
+ "country = ?"
+ "zip = ?"
+ ""
+ "WHERE email_address= ?";
try
{
ps = connection.prepareStatement(query);
ps.setString(1, user.getfName());
ps.setString(2, user.getlName());
ps.setString(3, user.getEmailAddress());
ps.setString(4, user.getPassword());
ps.setString(5, user.getDateOfBirth());
ps.setString(5, user.getPhone());
ps.setString(6, user.getAddress());
ps.setString(7, user.getCity());
ps.setString(8, user.getCountry());
ps.setString(9, user.getState());
ps.setString(10, user.getZipcode());
//ps.setString(11, user.getAccountType()); -- Ask Jassin
return ps.executeUpdate();
}
catch(SQLException e)
{
e.printStackTrace();
return 0;
}
finally
{
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
public static int delete(User user)
{
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
String query = "DELETE FROM User" +
"WHERE email_address = ?";
try
{
ps = connection.prepareStatement(query);
ps.setString(1, user.getEmailAddress());
return ps.executeUpdate();
}
catch(SQLException e)
{
e.printStackTrace();
return 0;
}
finally
{
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
public static boolean emailExists(String emailAddress)
{
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT email_address FROM User"+
"WHERE email_address = ?";
try
{
ps = connection.prepareStatement(query);
ps.setString(1, emailAddress);
rs = ps.executeQuery();
return rs.next();
}
catch(SQLException e)
{
e.printStackTrace();
return false;
}
finally
{
DBUtil.closeResultSet(rs);
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
public static User selectUser(String emailAddress)
{
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String query = "SELECT * FROM User"+
"WHERE email_address = ?";
try
{
ps = connection.prepareStatement(query);
ps.setString(1, emailAddress);
rs = ps.executeQuery();
User user = null;
if (rs.next())
{
user = new User();
user.setfName(rs.getString("fName"));
user.setlName(rs.getString("lName"));
user.setEmailAddress(rs.getString("emailAddress"));
user.setPassword(rs.getString("password"));
user.setPhone(rs.getString("phone"));
user.setDateOfBirth(rs.getString("dateOfBirth"));
user.setAddress(rs.getString("address"));
user.setCity(rs.getString("city"));
user.setCountry(rs.getString("country"));
user.setState(rs.getString("state"));
user.setZipcode(rs.getString("zip"));
// user.setAccountType(rs.getString("accountType")); -- Ask Jassin
}
return user;
}
catch(SQLException e)
{
e.printStackTrace();
return null;
}
finally
{
DBUtil.closeResultSet(rs);
DBUtil.closePreparedStatement(ps);
pool.freeConnection(connection);
}
}
}
这是 RegisterUserServlet:
package eBooks.controller;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.http.Cookie;
import eBooks.business.User;
import eBooks.business.Account;
import eBooks.Data.UserDB;
public class RegisterUserServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
HttpSession session = request.getSession();
String fName = request.getParameter("fName");
String lName = request.getParameter("lName");
String emailAddress = request.getParameter("emailAddress");
String password = request.getParameter("password");
String dateOfBirth = request.getParameter("dateOfBirth");
String phone = request.getParameter("phohe");
String address = request.getParameter("address");
String city = request.getParameter("city");
String country = request.getParameter("country");
String state = request.getParameter("country");
String accountType = request.getParameter("accountType");
//TO DO: Account acctTypeList = request.getParameter("acctTypeList"); add this an object first
User user = new User();
user.setfName(fName);
user.setlName(lName);
user.setEmailAddress(emailAddress);
user.setPassword(password);
user.setDateOfBirth(dateOfBirth);
user.setAddress(address);
user.setCity(city);
user.setCountry(country);
user.setState(state);
user.setZipcode(phone);
//TODO: user.setAccountType(accTypeList); -- Ask Jassin
// Add information to the database
if(UserDB.emailExists(emailAddress))
UserDB.update(user);
else
UserDB.update(user);
session.setAttribute("User", user);
Cookie emailCookie = new Cookie("emailCookie", emailAddress);
emailCookie.setMaxAge(60*60*24*365*2);
emailCookie.setPath("/");
response.addCookie(emailCookie);
String url = "WEB-INF/view/registration_confirmation.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
}
}
我是 Web 开发的新手,我只需要朝着正确的方向努力来解决这个问题。
我正在使用 glassfish 和 mysql。