1

当我尝试运行以下脚本时,我不断收到无效标识符异常:javax.servlet.ServletException: java.sql.SQLException: [Oracle][ODBC][Ora]ORA-00904: "CUSTID": invalid identifier

   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 
   conn = DriverManager.getConnection("jdbc:odbc:rreOracle","xxxxxx","xxxxxxxx"); 
   stmt = conn.createStatement(); 
  PreparedStatement preparedStatement;

      //get parameters from the request
      String custID=request.getParameter("cust_ID");
      String saleID=request.getParameter("sale_ID");
      String firstName=request.getParameter("first_Name");
      String mInitial=request.getParameter("mI");
      String lastName=request.getParameter("last_Name");
      String streetName=request.getParameter("street");
      String city=request.getParameter("city");
      String state=request.getParameter("state");
      String zipCode=request.getParameter("zip_Code");
      String DOB=request.getParameter("DOB");
      String agentID=request.getParameter("agent_ID");
      String homePhone=request.getParameter("home_Phone");
      String cellPhone=request.getParameter("cell_Phone");
      String profession=request.getParameter("profession");
      String employer=request.getParameter("employer");
      String referrer=request.getParameter("referrer");


   preparedStatement = conn.prepareStatement("UPDATE customer"
+ " SET customer.cust_ID=?, customer.sale_ID=?, customer.first_Name=?, customer.mI=?, customer.last_Name=?, customer.street_Name=?, customer.city=?, customer.state=?, customer.zip_Code=?,customer. DOB=?, customer.agent_ID=?, customer.home_Phone=?, customer.cell_Phone=?, customer.profession=?, customer.employer=?, customer.referrer=?"
+ " WHERE customer.cust_ID=custID ") ;

   preparedStatement.setInt(1, Integer.valueOf(custID));
   preparedStatement.setInt(2, Integer.valueOf(saleID));
   preparedStatement.setString(3, firstName);
   preparedStatement.setString(4, mInitial);
   preparedStatement.setString(5, lastName);
   preparedStatement.setString(6, streetName);
   preparedStatement.setString(7, city);
   preparedStatement.setString(8, state);
   preparedStatement.setString(9, zipCode);
   preparedStatement.setString(10, DOB);
   preparedStatement.setInt(11, Integer.valueOf(agentID));
   preparedStatement.setString(12, homePhone);
   preparedStatement.setString(13, cellPhone);
   preparedStatement.setString(14, profession);
   preparedStatement.setString(15, employer);
   preparedStatement.setString(16, referrer);

   preparedStatement.executeUpdate();
4

2 回答 2

9

你可以试试

<%preparedStatement = conn.prepareStatement("UPDATE customer"
+ " SET customer.cust_ID=?, customer.sale_ID=?, customer.first_Name=?, customer.mI=?, customer.last_Name=?, customer.street_Name=?, customer.city=?, customer.state=?, customer.zip_Code=?,customer. DOB=?, customer.agent_ID=?, customer.home_Phone=?, customer.cell_Phone=?, customer.profession=?, customer.employer=?, customer.referrer=?"
+ " WHERE customer.cust_ID=?") ;%>
<%preparedStatement.setString(17, custID );%>

或者

<%preparedStatement = conn.prepareStatement("UPDATE customer"
+ " SET customer.cust_ID=?, customer.sale_ID=?, customer.first_Name=?, customer.mI=?, customer.last_Name=?, customer.street_Name=?, customer.city=?, customer.state=?, customer.zip_Code=?,customer. DOB=?, customer.agent_ID=?, customer.home_Phone=?, customer.cell_Phone=?, customer.profession=?, customer.employer=?, customer.referrer=?"
+ " WHERE customer.cust_ID="+custID ) ;%>

希望能帮助到你。

于 2011-04-17T21:43:46.520 回答
3

在您的语句“WHERE customer.cust_ID=custID”的这一部分中,oracle 正在寻找一个名为“custID”的值。

此时,您的上下文中的变量名称不相关 - 在 SQL 中,“where A = B”语句指的是“列 A == 列 B” - 因为表中没有“custID”列,oracle 抱怨.

于 2011-04-17T20:50:13.813 回答