当我尝试将表单中的数据添加到我的数据库时,它给了我一个错误
例外
org.apache.jasper.JasperException: java.lang.NumberFormatException: null 根本原因
java.lang.NumberFormatException:空
This is my code
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="java.util.*"%>
<%@page import="java.io.*" %>
<%
String firstName = request.getParameter("firstName");
String secondName = request.getParameter("secondName");
String gender = request.getParameter("gender");
String address = request.getParameter("address");
String city = request.getParameter("city");
String country = request.getParameter("country");
int zip = Integer.parseInt(request.getParameter("zip"));
int mobileNo = Integer.parseInt(request.getParameter("mobileNo"));
int homePhone = Integer.parseInt(request.getParameter("homePhone"));
String eMail = request.getParameter("eMail");
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/testproject", "root", "123456");
Statement st = null;
PreparedStatement ps = null;
ResultSet rs = null;
ps = con.prepareStatement("INSERT INTO studentregform (firstName, secondName, gender, address, city, country, zip, mobile, homePhone, email) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
ps.setString(1, firstName);
ps.setString(2, secondName);
ps.setString(3, gender);
ps.setString(4, address);
ps.setString(5, city);
ps.setString(6, country);
ps.setInt(7, zip);
ps.setInt(8, mobileNo);
ps.setInt(9, homePhone);
ps.setString(10, eMail);
int result = ps.executeUpdate();
} catch (Exception e) {
//out.println("Data not inserted");
throw new Error(e);
}
%>
谁可以帮我这个事?谢谢你。