2

I'm trying to get the file handle from plsq, I'm trying to see if I can test plsql packages from Java I have this code:

Properties props = Utils.readProps("database.properties");
    Connection con = DBManager.getConnection(props.getProperty("url"), props.getProperty("username"), props.getProperty("password"));
    Object file_type = new Object[3];
    STRUCT oracleRecord;
        try {
            //StructDescriptor fileType = StructDescriptor.createDescriptor("UTL_FILE.FILE_TYPE",con);
            CallableStatement stmt = con.prepareCall("{call simple_test.caller(?,?,?)");
            stmt.setObject(1, "/u01/home/oracle/EI/278");
            stmt.setObject(2, "ql_item_test.txt");
            stmt.registerOutParameter(3, OracleTypes.STRUCT, "UTL_FILE.FILE_TYPE");
            stmt.execute();
            oracleRecord = ((OracleCallableStatement)stmt).getSTRUCT(3);
            file_type = oracleRecord.getAttributes();
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

And this plsql code:

PROCEDURE caller(file_path VARCHAR2,
                                         file_name VARCHAR2,
                                         fp        OUT UTL_FILE.file_type) IS
                maxLineSize INTEGER;
        BEGIN
                maxLineSize := 1024;
                fp          := UTL_FILE.FOPEN(file_path, file_name, 'R', maxLineSize);
        END;

But When I ran it I guess this error:

java.sql.SQLException: invalid name pattern: UTL_FILE.FILE_TYPE

I'm I getting this error because I can't pass/retrieve plsql types?

4

1 回答 1

1

UTL_FILE.FILE_TYPE 是 PL/SQL“记录”,Oracle JDBC 不支持记录。它确实支持对象以及某些对象和原语的集合。请参阅http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraoor.htm http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraarr.htmhttp: //docs.oracle.com/cd/E11882_01/java.112/e16548/oraoot.htm#i1078761

顺便说一句,无论如何,我看不出你会用Java做什么......

于 2013-08-22T20:41:33.930 回答