1
가입 : 2010년 6월 7일가 게시물 : 1삽입 저장 프로 시저 값은 SQL 테이블에 저장되지
[포스트 뉴]에 게시 오늘 오전 12시 53분 46초 견적 편집 도와주세요,
AM struts2 프레임 작업을 사용하여 db 메서드에 값을 보내고, 코드를 작성했습니다. try try 블록이 콘솔에서 오류 메시지를 실행하지 않았습니다. msg 저장 프로 시저 exe succ가 표시되지만 내 값이 테이블에 삽입되지 않습니다. SQL 저장 프로 시저에서 4 개의 입력 매개 변수와 4 개의 출력 매개 변수가 제공되었습니다. 출력 매개 변수가 아닌 입력 params에 대한 값을 디버그 모드로 가져옵니다. 여기서이 코드를 추가하면이 버그를 해결할 수 있습니다. . 질문을 다시 읽기 후 편집
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;
}
}