Java PreparedStatement错误

时间:2012-03-26 09:45:00

标签: java sql

我有以下代码。它试图基本上处理从jsf表单提交的数据,然后将数据插入数据库中的表。现在我们安装的数据库已经很老了......它是sql server 2000所以我用jtds作为驱动程序。代码:

 public void dbConnect(String db_connect_string,
            String db_userid,
            String db_password)
    {
      try {
         Class.forName("net.sourceforge.jtds.jdbc.Driver");
         Connection conn = DriverManager.getConnection(db_connect_string,
                  db_userid, db_password);
         System.out.println("connected");
         dateSubmitted = "dasdasd";
         /*HERE THE STATEMENTS TO INSERT*/
         java.sql.PreparedStatement insertData = null;
         String insertStatement = "INSERT INTO SLMDATA VALUES(?,?,?,?,?,?,?,?,?,?,"
                 + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
         insertData = conn.prepareStatement(insertStatement);
         insertData.setString(1, serviceLogger); 
         insertData.setString(2, dateSubmitted);
         insertData.setString(3, serviceName);
         insertData.setString(4, department);
         insertData.setString(5, division);
         insertData.setString(6, businessServiceDescription );
         insertData.setString(7, technicalServiceDescription);
         insertData.setString(8, serviceCustomer);
         insertData.setString(9, serviceCriticality);
         insertData.setString(10, serviceRequestSystem);
         insertData.setString(11, serviceCategory);
         insertData.setString(12, serviceHours );
         insertData.setString(13, availabilityTarget);
         insertData.setString(14, lowIncidentResponseScale );
         insertData.setString(15, lowIncidentResponseHrsType );
         insertData.setString(16, lowResponseTimeText);
         insertData.setString(17, mediumIncidentResponseScale);
         insertData.setString(18, mediumIncidentResponseHrsType);
         insertData.setString(19, mediumResponseTimeText);
         insertData.setString(20, highIncidentResponseScale);
         insertData.setString(21, highIncidentResponseHrsType );
         insertData.setString(22, highResponseTimeText );
         insertData.setString(23, lowIncidentResolutionScale );
         insertData.setString(24, lowIncidentResolutionHrsType );
         insertData.setString(25, lowResolutionTimeText );
         insertData.setString(26, mediumIncidentResolutionScale );
         insertData.setString(27, mediumIncidentResolutionHrsType );
         insertData.setString(28, mediumResolutionTimeText );
         insertData.setString(29, highIncidentResolutionScale );
         insertData.setString(30, highIncidentResolutionHrsType);
         insertData.setString(31, highResolutionTimeText );
         insertData.setString(32, blockTime );
         insertData.setString(33, impactedServices);
         insertData.setString(34, operationalDependencies );
         insertData.setString(35, disasterAvailable );
         insertData.setString(36, configurationItems );
         insertData.executeUpdate();

         conn.close();
         FacesContext.getCurrentInstance().getExternalContext().dispatch("thankyou.xhtml");

      } catch (Exception e) {
         e.printStackTrace();
      }
    }


    public void callConnection(){

        dbConnect("jdbc:jtds:sqlserver://host;", "username",
                   "password");
    }

并且glassfish服务器控制台输出显示:

  

java.sql.SQLException:无效的对象名称'SLMDATA'。

SLMDATA是表的名称,我确定它是正确的。当我通过断点功能逐步执行代码时,我会到达executeQuery,然后事情就会失控。我查看了所有变量的内容,并且都是有效的。知道发生了什么事吗?被困在这一段时间

1 个答案:

答案 0 :(得分:1)

您应该尝试将模式名称放在表schemaName.table之前,或者在数据库中为模式创建一个同义词。