为什么我不断收到此空指针未知源错误?
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)
);
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)
I am trying
//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 table
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)
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在prepareStatement中使用这样的语法
来定义查询的参数。
之后您可以为prepareStatement设置参数。 NPE 发生是因为您尝试设置 sql 语句缺少参数。
In prepareStatement use syntax like this
to define parameter of query.
After that you can set parameters to prepareStatement. NPE occurs because you trying to set missing parameter of sql statement.
最有可能的是,firstName 为空。
Most likely, firstName is null.