2012-09-27 22 views
0

我有一個用java編寫的方法來執行INSERT,UPDATE和DELETE模式的SQL語句。這對WebSphere 6.1起作用,在升級到WebSphere 7.0後,它停止工作。Java - 更新管理表時出錯

下面是我的代碼:

public void executeSQL() throws SQLException, ParseException, NamingException 
{ 
    // Get a Connection from the Connection Pool if the connection is closed 
    Connection dbCon = DriverUtilities.getConnectionFromContext(DriverUtilities.DIRECTPAY_DB); 

    // create a Statment object whose ResultSet is scroll sensitive and with Concurrent Updatable. 
    Statement stmt = dbCon.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); 
    dbCon.setAutoCommit(true); 

    String strColumn = null; 
    String colName = null; 
    String colVal = null; 
    String colType = null; 

    String sql = null; 

    try { 
    if (isUpdate | isDelete) { 
     //ResultSet rs = stmt.executeQuery("select * from " + getTableName()); 

     ResultSet rs = stmt.executeQuery("select * from " + getSqlFrom()); 

     //Move the ResultSet to the Row Index  
     rs.absolute(iRowIndex + 1); 

     Enumeration enum1 = ColNames.elements(); 

     int i = 1; 

     // Update Block 
     if (isUpdate) { 
      while (enum1.hasMoreElements()) { 
       //column name for update 
       strColumn = (String) enum1.nextElement(); 

       // value from the screen 
       colVal = (String) requestParams.get("post" + strColumn); 

       //get column type 
       colType = colTypeHash.get(strColumn).toString(); 

       //if colvalue from screen not null then test for the Column type 
       if ((colVal == null) || (colVal.equalsIgnoreCase("null"))){ 
        rs.updateNull(i);        
       } else { 
        if ((colType.equalsIgnoreCase("INT")) || (colType.equalsIgnoreCase("SMALLINT"))) { 
         if (colVal.trim().length() > 0) 
          rs.updateInt(i, Integer.parseInt(colVal)); 
        } else if ((colType.equalsIgnoreCase("DATETIME"))) { 
         if (colVal.trim().length() > 0) 
          rs.updateTimestamp(i, toTimestamp(colVal)); 
        } else if ((colType.equalsIgnoreCase("CHAR"))) { 
         //if (colVal.trim().length() > 0) 
          rs.updateString(i, colVal); 
        } else if ((colType.equalsIgnoreCase("NVARCHAR"))) { 
         //if (colVal.trim().length() > 0) 
          rs.updateString(i, colVal); 
        } else if ((colType.equalsIgnoreCase("VARCHAR"))) { 
         //if (colVal.trim().length() > 0) 
          rs.updateString(i, colVal); 
        } else if ((colType.equalsIgnoreCase("DECIMAL"))) { 
         if (colVal.trim().length() > 0) 
          rs.updateString(i, colVal); 
        } else if ((colType.equalsIgnoreCase("FLOAT"))) { 
         if (colVal.trim().length() > 0) 
          rs.updateDouble(i, Double.parseDouble(colVal)); 
        } else if ((colType.equalsIgnoreCase("BIT"))) { 
         if (colVal.trim().length() > 0) 
          rs.updateByte(i, Byte.parseByte(colVal)); 
         //rs.updateDouble(i, Double.parseDouble(colVal)); 
        } else if ((colType.equalsIgnoreCase("int identity"))) { 
         // ignore it 
        } else { 
         System.out.println("WARNING DATATYPE UNSUPPORTED in ADMIN: " + colType); 
        } 
       } 

       i++; 
      } 
      //Setting Identity Insert ON. 
      stmt.executeUpdate("SET IDENTITY_INSERT "+getTableName()+" ON"); 
      rs.updateRow(); 
     } 

     //delete block 
     if (isDelete) { 
      rs.deleteRow(); 
     } 

     rs.close(); 
    } 

    //Insert Block 
    if (isInsert) { 
     //Setting Identity Insert ON. 
     stmt.executeUpdate("SET IDENTITY_INSERT "+getTableName()+" ON"); 
     // get the SQL statement for Insert   
     sql = getSQL(); 

     int resultFlag = stmt.executeUpdate(sql); 
    } 
    //Setting Identity Insert OFF. 
    stmt.executeUpdate("SET IDENTITY_INSERT "+getTableName()+" OFF"); 
    stmt.close(); 
    dbCon.close(); 

    } catch (SQLException e) { 
     System.out.println("executeSQL failed: " + sql + ", " + StackTraces.getStackTrace(e)); 
     try { 
      stmt.close(); 
     } catch(Exception ee){ 
     } 
     try { 
      dbCon.close(); 
     } catch(Exception ee){ 
     } 
     throw (e); 

    } catch (java.lang.NumberFormatException e) { 
     System.out.println("executeSQL failed: " + sql + ", " + StackTraces.getStackTrace(e)); 
     try { 
      stmt.close(); 
     } catch(Exception ee){ 
     } 
     try { 
      dbCon.close(); 
     } catch(Exception ee){ 
     } 
     throw (e); 
    } 
} 

下面是我的錯誤堆棧跟蹤:

[9/27/12 16:28:06:497 GMT-06:00] 0000002a SystemOut  O ---------------- sql = SELECT * FROM PRODUCT ------------------------ 
[9/27/12 16:28:06:664 GMT-06:00] 0000002a SystemOut  O ERROR: 
[9/27/12 16:28:06:685 GMT-06:00] 0000002a WSRdbManagedC W DSRA1300E: Feature is not implemented: javax.sql.PooledConnection.addStatementEventListener 
[9/27/12 16:28:37:378 GMT-06:00] 0000002e SystemOut  O executeSQL failed: null, com.microsoft.sqlserver.jdbc.SQLServerException: Cannot find the object "PRODUCT" because it does not exist or you do not have permissions. 
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:775) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676) 
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575) 
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:633) 
    at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.pmiExecuteUpdate(WSJdbcStatement.java:1693) 
    at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeUpdate(WSJdbcStatement.java:1041) 
    at com.bcbskc.bbb.directpay.admin.AdminTableBean.executeSQL(AdminTableBean.java:313) 
    at com.bcbskc.bbb.directpay.admin.AdminTableBean.manipulateTable(AdminTableBean.java:132) 
    at com.bcbskc.bbb.directpay.actions.ManipulateAdminTableAction.manipulateTable(ManipulateAdminTableAction.java:104) 
    at com.bcbskc.bbb.directpay.actions.ManipulateAdminTableAction.execute(ManipulateAdminTableAction.java:46) 
    at com.bcbskc.bbb.common.uiframework.Controller.doPost(Controller.java:56) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131) 
    at com.bcbskc.bbb.common.security.AuthbeanFilter.doFilter(AuthbeanFilter.java:88) 
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179) 
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91) 
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864) 
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583) 
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305) 
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83) 
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) 
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604) 

[9/27/12 16:28:37:379 GMT-06:00] 0000002e SystemOut  O ManipulateAdminTableAction failed: There was an error updating the admin table. Please check the data for errors and format. com.microsoft.sqlserver.jdbc.SQLServerException: Cannot find the object "PRODUCT" because it does not exist or you do not have permissions.com.microsoft.sqlserver.jdbc.SQLServerException: Cannot find the object "PRODUCT" because it does not exist or you do not have permissions. 
    at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.doExecuteStatement(SQLServerStatement.java:775) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement$StmtExecCmd.doExecute(SQLServerStatement.java:676) 
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575) 
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154) 
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeUpdate(SQLServerStatement.java:633) 
    at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.pmiExecuteUpdate(WSJdbcStatement.java:1693) 
    at com.ibm.ws.rsadapter.jdbc.WSJdbcStatement.executeUpdate(WSJdbcStatement.java:1041) 
    at com.bcbskc.bbb.directpay.admin.AdminTableBean.executeSQL(AdminTableBean.java:313) 
    at com.bcbskc.bbb.directpay.admin.AdminTableBean.manipulateTable(AdminTableBean.java:132) 
    at com.bcbskc.bbb.directpay.actions.ManipulateAdminTableAction.manipulateTable(ManipulateAdminTableAction.java:104) 
    at com.bcbskc.bbb.directpay.actions.ManipulateAdminTableAction.execute(ManipulateAdminTableAction.java:46) 
    at com.bcbskc.bbb.common.uiframework.Controller.doPost(Controller.java:56) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1657) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1597) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131) 
    at com.bcbskc.bbb.common.security.AuthbeanFilter.doFilter(AuthbeanFilter.java:88) 
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:934) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:502) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:179) 
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91) 
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864) 
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583) 
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305) 
    at com.ibm.ws.http.channel.inbound.impl.HttpICLReadCallback.complete(HttpICLReadCallback.java:83) 
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) 
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1604) 

回答