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

发布于 2024-11-02 12:52:04 字数 1618 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

薆情海 2024-11-09 12:52:04

在prepareStatement中使用这样的语法

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

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

In prepareStatement use syntax like this

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

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.

飞烟轻若梦 2024-11-09 12:52:04

最有可能的是,firstName 为空。

Most likely, firstName is null.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文