gpt4 book ai didi

java - java中插入存储过程值未存储在sql表中

转载 作者:行者123 更新时间:2023-12-01 05:54:30 26 4
gpt4 key购买 nike

加入时间:2010 年 6 月 7 日帖子数:1

[发布新内容]今天发布 12:53:46 AM报价编辑帮帮我,

AM使用struts2框架工作,正在将值发送到db方法,并且我已经编写了代码,我的try block 在控制台中执行没有err msg,我得到msg存储过程exe succ,但我的值没有插入到表中。在sql存储过程中已经给出了4个输入参数和4个输出参数。我在 Debug模式下获取输入参数值的值,我获取该表单 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;
}
}

最佳答案

重读问题后编辑:

如果 getAppName().length 为零,则不会调用执行。会是这样吗?

关于java - java中插入存储过程值未存储在sql表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3497096/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com