当我尝试从Oracle过程中检索对象类型时,我收到了正确的数字,但是这个程序传递给我的所有字符串都是“???”。 我的例子:
import oracle.sql.ARRAY;
import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;
import java.sql.Array;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSetMetaData;
import java.sql.Struct;
import java.sql.Types;
public class InitMethod {
public static void init() throws Exception {
Class.forName("oracle.jdbc.OracleDriver");
Connection connection =
DriverManager.getConnection("jdbc:oracle:thin:@10.0.0.20:1521:dw", "user", "password");
final String typeName = "T_DEMO_OBJECT";
final String typeTableName = "T_DEMO_OBJECTS";
final StructDescriptor structDescriptor = StructDescriptor.createDescriptor(typeName.toUpperCase(), connection);
final ResultSetMetaData metaData = structDescriptor.getMetaData();
CallableStatement cs = connection.prepareCall("{call p_generate_demo_objects(?, ?)}");
cs.setInt(1, 7);
cs.registerOutParameter(2, Types.ARRAY, typeTableName);
cs.execute();
Object[] data = (Object[]) ((Array) cs.getObject(2)).getArray();
for (Object tmp : data) {
Struct row = (Struct) tmp;
int idx = 1;
for (Object attribute : row
.getAttributes()) {
System.out.println(metaData.getColumnName(idx) + " = " + attribute);
++idx;
}
System.out.println("---");
}
cs.close();
}
我收到正确的数字,但所有字符串都是“???”:
SOME_NUMBER = 1 SOME_STRING = ???
SOME_NUMBER = 2 SOME_STRING = ???
可能是什么问题?
(我使用ojdbc6.jar)
答案 0 :(得分:1)
当您在类路径中不包含orai18n.jar且数据库字符集不在此列表中时,会发生这种情况:ASCII,UTF8或ISOLATIN1。所有字符都替换为“替换字符”,即“?”。你可以从OTN下载orai18n.jar(在谷歌搜索“oracle jdbc download”)。
答案 1 :(得分:0)
In my company, we have columns of PII data in certain Oracle database schema that are redacted and replaced by a custom string. It seems likely that the '???' sequence to be a data redaction in the table. You might check with your DB Admin to see if this is the case.