加入:2010年6月7日 帖子:1
[发布新帖]今天上午12:53:46发布 引用编辑 帮助我,
AM使用struts2框架工作,我将值发送到db方法并且我已经编写了代码,我的try块在控制台中执行了没有错误的msg,我得到了msg存储过程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 :(得分:0)
重新阅读问题后编辑:
如果getAppName()。length为零,则不会调用execute。可能是这种情况吗?