从 oracle 存储过程返回到 Java 的字符串,带有 '???'
我的 Java 代码调用 Oracle DB 中的存储过程并返回带有某些字段的对象。 当我从对象中找出属性时 - 我的字符串有问题。字符串变成“???” (3 个问号)而且不应该是这样! (整数返回正常)
我在数据库上测试了我的存储过程 - 它运行良好。
我使用调用数据库的小型本地主程序测试了我的 Java 代码 - 它运行良好。 (数据库的连接是直接使用 DriverManager.getConnection("jdbc:oracle:thin:@......); )
当我在我的大项目中使用我的存储过程来连接到数据库时,问题就出现了 //
你知道当我使用 WebLogic 时如何从数据库获取正确的字符串吗?
:
PROCEDURE SearchOrder (InWoArr IN WoTab,
OutWoAccStat OUT WoAccStatTab) as
outRec WoAccStatType;
wo number(10);
acc number(10);
stat varchar2(2);
begin
OutWoAccStat := WoAccStatTab();
for i in InWoArr.FIRST .. InWoArr.LAST loop
OutWoAccStat.EXTEND;
begin
select work_order_number,account_number,' '
into wo,acc,stat
from table1
where work_order_number=InWoArr(i);
....
outRec := WoAccStatType(wo,acc,stat);
OutWoAccStat(i) := outRec;
exception
when no_data_found then
outRec := WoAccStatType(InWoArr(i),0,' ');
OutWoAccStat(i) := outRec;
end;
end loop;
end SearchOrder;
Array of 200
create or replace type poldev_dba.WoAccStatTab as VARRAY(200) of WoAccStatType
//The array type
create or replace type poldev_dba.WoAccStatType as object (work_order_number number(10), account_number number(10), wo_status varchar2(2))
//Java 代码
//Store Procedure Name
CallableStatement cs = (CallableStatement) con.prepareCall("{ call spp.SearchOrder( ?, ? )}");
//input:
cs.setArray(1,woInput);
//Output:
cs.registerOutParameter(2,OracleTypes.ARRAY,"WOACCSTATTAB");
//Run the query...
cs.execute();
//Retrieve Array:
woAccArray = (ARRAY)cs.getArray(2);
woAccRecs = (Object[])woAccArray.getArray();
int wo = 0;
int acc = 0;
String stat;
for (int i = 0; i < woAccRecs.length; i++) {
/* Since we don't know the type of the record, get it into STRUCT !! */
STRUCT woAccRec = (oracle.sql.STRUCT)woAccRecs[i];
/* Get the attributes - nothing but the columns of the table */
Object[] attributes = woAccRec.getAttributes();
/* attribute 0 - work order */
wo = Integer.parseInt("" + attributes[0]);
/* attribute 1 - account number */
acc = Integer.parseInt("" + attributes[1]);
/* attribute 2 - status */
stat = (String) attributes[2];
/*PROBLEM!!!! stat returned value '???'*/
System.out.println("wo = " + wo + ",acc = " + acc +", status = "+stat);
My code in Java calls stored procedure in Oracle DB and returns object with some fields.
When I find out the attributes from the Object - I have problem with the string. The string becomes '???' (3 questtion marks) and it not supposed to be that!
(integer returned OK)
I tested my stored procedure on the DB - It worked well.
I tested my Java code with small local main program that call to the DB - and it worked well. (The connection the the DB was direct with DriverManager.getConnection("jdbc:oracle:thin:@......); )
The problem came when I used my store procedure in my big project that connect to the DB with the weblogic.
Do you know how to get the right string from the DB when I work with the WebLogic?
Oracle code:
PROCEDURE SearchOrder (InWoArr IN WoTab,
OutWoAccStat OUT WoAccStatTab) as
outRec WoAccStatType;
wo number(10);
acc number(10);
stat varchar2(2);
begin
OutWoAccStat := WoAccStatTab();
for i in InWoArr.FIRST .. InWoArr.LAST loop
OutWoAccStat.EXTEND;
begin
select work_order_number,account_number,' '
into wo,acc,stat
from table1
where work_order_number=InWoArr(i);
....
outRec := WoAccStatType(wo,acc,stat);
OutWoAccStat(i) := outRec;
exception
when no_data_found then
outRec := WoAccStatType(InWoArr(i),0,' ');
OutWoAccStat(i) := outRec;
end;
end loop;
end SearchOrder;
//Array of 200
create or replace type poldev_dba.WoAccStatTab as VARRAY(200) of WoAccStatType
//The array type
create or replace type poldev_dba.WoAccStatType as object (work_order_number number(10), account_number number(10), wo_status varchar2(2))
//Java code:
//Store Procedure Name
CallableStatement cs = (CallableStatement) con.prepareCall("{ call spp.SearchOrder( ?, ? )}");
//input:
cs.setArray(1,woInput);
//Output:
cs.registerOutParameter(2,OracleTypes.ARRAY,"WOACCSTATTAB");
//Run the query...
cs.execute();
//Retrieve Array:
woAccArray = (ARRAY)cs.getArray(2);
woAccRecs = (Object[])woAccArray.getArray();
int wo = 0;
int acc = 0;
String stat;
for (int i = 0; i < woAccRecs.length; i++) {
/* Since we don't know the type of the record, get it into STRUCT !! */
STRUCT woAccRec = (oracle.sql.STRUCT)woAccRecs[i];
/* Get the attributes - nothing but the columns of the table */
Object[] attributes = woAccRec.getAttributes();
/* attribute 0 - work order */
wo = Integer.parseInt("" + attributes[0]);
/* attribute 1 - account number */
acc = Integer.parseInt("" + attributes[1]);
/* attribute 2 - status */
stat = (String) attributes[2];
/*PROBLEM!!!! stat returned value '???'*/
System.out.println("wo = " + wo + ",acc = " + acc +", status = "+stat);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在别处。 Oracle DB 和 DB 驱动程序都不会用
???
替换结果列。在您的产品代码中搜索该字符串以了解使用它的原因。The problem is elsewhere. Neither the Oracle DB nor the DB driver will replace a result column with
???
. Search the code of your product for this string to see why it is used.