java callable语句帮助使用包过程
目前,我在包下有一个程序,当某些人在网页上选择 user_id 时,它会获取 user_name ,但现在我想通过将 ssn 添加到页面来更改格式,以便当某些主体选择 user_id 时,它会在网页文本框中加载用户名和 ssn ..我我正在使用可调用语句来加载数据..我可以在此处更改什么来获取用户名和 ssn
PROCEDURE get_User_name
(
return_code_out OUT VARCHAR2,
return_msg_out OUT VARCHAR2,
user_id_in IN user.user_id%TYPE,
user_name_out OUT user.user_name%TYPE
)
IS
BEGIN
return_code_out := '0000';
return_msg_out := 'OK';
SELECT c.user_name INTO user_name_out
FROM user c
WHERE c.user_id = user_in;
END get_user_name;
,这是我的加载函数
public String load() {
String retMsg = null;
DbUtil db = null;
java.sql.CallableStatement cstmt = null;
try {
db = new DbUtil();
cstmt = db.prepareCall("{ call sample.PACK_USER.get_user_name(?, ?, ?, ?) }");
cstmt.registerOutParameter(1,OracleTypes.VARCHAR);
cstmt.registerOutParameter(2,OracleTypes.VARCHAR);
cstmt.setString(3,this.getuserid());
cstmt.registerOutParameter(4,OracleTypes.VARCHAR);
cstmt.execute();
if (cstmt.getString(1).equals(Constants.dbSuccess))
myLog.log(myLog.INFORMATION, "UserBean.load() DB return code and message = " + retMsg);
else {
retMsg = cstmt.getString(1) + " - " + cstmt.getString(2);
myLog.log(myLog.ERROR, "UserBean.load() DB return code and message = " + retMsg);
}
this.setUserName(cstmt.getString(4));
return retMsg;
}
Currently i have this procedure under package that gets user_name when some selects user_id on web page but now i wanna change the format by adding ssn to the page so when some body selects user_id it loads user name as well as ssn on webpage textbox.. i am using callable statement to load data.. what can i change here to get both user name and ssn
PROCEDURE get_User_name
(
return_code_out OUT VARCHAR2,
return_msg_out OUT VARCHAR2,
user_id_in IN user.user_id%TYPE,
user_name_out OUT user.user_name%TYPE
)
IS
BEGIN
return_code_out := '0000';
return_msg_out := 'OK';
SELECT c.user_name INTO user_name_out
FROM user c
WHERE c.user_id = user_in;
END get_user_name;
and here is my load function
public String load() {
String retMsg = null;
DbUtil db = null;
java.sql.CallableStatement cstmt = null;
try {
db = new DbUtil();
cstmt = db.prepareCall("{ call sample.PACK_USER.get_user_name(?, ?, ?, ?) }");
cstmt.registerOutParameter(1,OracleTypes.VARCHAR);
cstmt.registerOutParameter(2,OracleTypes.VARCHAR);
cstmt.setString(3,this.getuserid());
cstmt.registerOutParameter(4,OracleTypes.VARCHAR);
cstmt.execute();
if (cstmt.getString(1).equals(Constants.dbSuccess))
myLog.log(myLog.INFORMATION, "UserBean.load() DB return code and message = " + retMsg);
else {
retMsg = cstmt.getString(1) + " - " + cstmt.getString(2);
myLog.log(myLog.ERROR, "UserBean.load() DB return code and message = " + retMsg);
}
this.setUserName(cstmt.getString(4));
return retMsg;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因此,这就是按照 Rajesh 建议更改您的过程(尽管它确实取决于您使用的数据库服务器):
并按如下方式更改 Java 代码:
您现有的错误代码将永远不会工作 - 您必须通过在某处捕获 SQLException 来处理错误。
So that is change your procedure as Rajesh suggested (though it does depend on which database server you are using):
AND change the Java code as follows:
Your existing error code would never work - you must handle errors by catching an SQLException somewhere.
该过程需要更改为...
从您的代码来看,您似乎想从过程中返回错误代码和错误消息。相反,请使用 try catch 块来捕获 Java 中的 sqlException 并采取必要的操作。
The procedure would need to be changed to...
From your code, it looks like you want to return the error code and error message out from the procedure. Instead, use the try catch block to catch the sqlException in Java and take the necessary action.