org.apache.jasper.JasperException: An exception occurred processing JSP page /customerDelete.jsp at line 39
java.lang.NullPointerException
sun.jdbc.odbc.JdbcOdbcPreparedStatement.clearParameter(Unknown Source)
我正在尝试
//get parameters from the request
String firstName=request.getParameter("first_Name");
String lastName=request.getParameter("last_Name");
preparedStatement = conn.prepareStatement("DELETE FROM customer "
+ " WHERE customer.first_Name= " +firstName
+ " AND customer.last_Name= " +lastName);
preparedStatement.setString(1, firstName); // line 39
preparedStatement.setString(2, lastName);
preparedStatement.executeUpdate();
SQL表
CREATE TABLE customer
(cust_ID NUMBER NOT NULL,
sale_ID NUMBER NOT NULL,
first_Name VARCHAR2(30) NOT NULL,
mI VARCHAR2(2) ,
last_Name VARCHAR2(50) NOT NULL,
street_Name VARCHAR2(50) ,
city VARCHAR2(30) NOT NULL,
state VARCHAR2(50) NOT NULL,
zip_Code VARCHAR2(5) NOT NULL,
DOB DATE ,
agent_ID NUMBER ,
home_Phone VARCHAR2(12) UNIQUE,
cell_Phone VARCHAR2(12) UNIQUE,
profession VARCHAR2(30) ,
employer VARCHAR2(30) ,
referrer VARCHAR2(30)
);
答案 0 :(得分:5)
在prepareStatement中使用这样的语法
delete from customer where customer.last_Name= ? and customer.first_Name= ?
定义查询参数。 之后,您可以将参数设置为prepareStatement。发生NPE是因为您尝试设置sql语句的缺失参数。
答案 1 :(得分:1)
最有可能的是,firstName为null。