为什么我一直得到这个空指针未知源错误?

Mik*_*ike 0 java sqlplus jdbc

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)
Run Code Online (Sandbox Code Playgroud)

我在尝试

      //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();
Run Code Online (Sandbox Code Playgroud)

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)            
    );      
Run Code Online (Sandbox Code Playgroud)

Vik*_*mov 5

在prepareStatement中使用这样的语法

delete from customer where customer.last_Name= ? and customer.first_Name= ? 
Run Code Online (Sandbox Code Playgroud)

定义查询参数.之后,您可以将参数设置为prepareStatement.发生NPE是因为您尝试设置sql语句的缺失参数.