gpt4 book ai didi

java - 为什么我不断收到此空指针未知源错误?

转载 作者:行者123 更新时间:2023-12-01 16:39:17 25 4
gpt4 key购买 nike

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)
);

最佳答案

在prepareStatement中使用这样的语法

delete from customer where customer.last_Name= ? and customer.first_Name= ? 

定义查询参数。之后您可以为prepareStatement设置参数。发生NPE是因为您尝试设置sql语句缺少参数。

关于java - 为什么我不断收到此空指针未知源错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5697621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com