2010-08-16 75 views
1

加入時間:2010年6月7日 帖子:1插入存儲過程的價值沒有得到存儲在SQL表

[發佈新]今天發佈的上午12點53分46秒 報價編輯 幫幫我,

上午使用struts2框架工作,我正在發送值的數據庫方法,我已經寫了代碼,我的try塊在控制檯中執行沒有錯誤味精,我得到了味精存儲過程EXE succ,但我的價值觀沒有得到插入表。在SQL存儲過程中,已經給出了4個輸入參數和4個輸出參數。我在調試模式下獲得了輸入參數的值,我得到了這個表單bean,但不是輸出參數,在這裏我添加了我的代碼,請幫助我解決這個問題。

package db; 

import java.util.List; 
import java.sql.*; 

import hbsbean.AddNewFieldsBean; 

public class ApplicationStoredDB { 
    public List<AddNewFieldsBean> storeNewRecords(AddNewFieldsBean bean) { 
     List<AddNewFieldsBean> nbean = null; 
     Connection conn = null; 
     String jdbcDriver = "sun.jdbc.odbc.JdbcOdbcDriver"; 
     String dbURL = "jdbc: odbc:sqlserver"; 
     String usernameDbConn = "root"; 
     String passwordDbConn = "hbsroot"; 
     try { 
      Class.forName(jdbcDriver).newInstance(); 
      conn = DriverManager.getConnection(dbURL, usernameDbConn, 
        passwordDbConn); 
     } catch (Exception e) { 
      System.out.println("jdbc driver not found:" + dbURL); 
      e.printStackTrace(); 
     } 

     try { 
      // make a callable statement for a stored procedure. 

      CallableStatement cstmt = conn 
        .prepareCall("{call proc_application_menu(?, ?, ?, ?, ?, ?, ? ,?)}"); 

      // set the values of the stored procedure's input parameters 

      System.out.println("calling stored procedure . . ."); 
      for (int i = 0; i < bean.getAppName().length; i++) { 

       cstmt.setString(1, bean.getAppName()[i]); 
       cstmt.setString(2, bean.getBasepath()[i]); 
       cstmt.setString(3, bean.getDesc()[i]); 
       cstmt.setString(4, bean.getUsername()); 

       // output params in sql 
       cstmt.registerOutParameter(5, Types.INTEGER); 
       cstmt.registerOutParameter(6, Types.INTEGER); 
       cstmt.registerOutParameter(7, Types.VARCHAR); 
       cstmt.registerOutParameter(8, Types.VARCHAR); 
       cstmt.execute(); 
      } 
      // now that the input parameters are set, we can proceed to execute 
      // the insertTheForm stored procedure 

      cstmt.close(); 
      System.out.println("Stored procedure executed succesfully....."); 
     } 

     catch (SQLException e) { 
      System.out.println("error: " + e); 
      e.printStackTrace(); 

     } 

     return nbean; 
    } 
} 

回答

0

重讀問題後編輯:

的執行將不會被調用,如果getAppName()長度爲零。情況會是這樣嗎?