問題描述: 我想通過java代碼調用存儲在我的數據庫中的過程。我想調用的過程有一個類型爲'MAP_VARCHAR'的參數(我已經將它定義爲下面的包中的類型)。java.sql.SQLException:從jdbc執行程序包級別類型時無效的列類型
現在,我試圖從我的java代碼執行此過程,但傳遞參數是給java.sql.SQLException。
SQL包來告訴你怎麼創建我的SQL程序,並輸入
--------------------------------------------------------
-- Package Body TEST_PACKAGET
--------------------------------------------------------
CREATE OR REPLACE EDITIONABLE PACKAGE BODY "TEST_PACKAGE" AS
PROCEDURE PerformersRole(P_Performer_Map MAP_VARCHAR) AS
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello ' || P_Performer_Map('Engineer'));
END PerformersRole;
END TEST_PACKAGE;
/
--------------------------------------------------------
-- Package TEST_PACKAGE
--------------------------------------------------------
CREATE OR REPLACE EDITIONABLE PACKAGE "TEST_PACKAGE" AS
/* TODO enter package declarations (types, exceptions, methods etc) here */
TYPE MAP_VARCHAR IS TABLE OF VARCHAR(100) INDEX BY VARCHAR(100);
PROCEDURE PerformersRole(P_Performer_Map MAP_VARCHAR);
END TEST_PACKAGE;
/
我的Java代碼
public void executeProcedure(){
CallableStatement statement = null;
try {
/// Oracle Connection code should be here
Connection connection = connectionManager.createConnection();
Hashtable newMap = new Hashtable();
newMap.put("Engineer", "Hanson");
newMap.put("Assistant", "Alice Kim");
newMap.put("Supervisor", "James MaCoy");
StringBuffer procedure = new StringBuffer("{call TEST_PACKAGE.PerformersRole(?) }");
statement = connection.prepareCall(procedure.toString());
statement.setInt(1, newMap);
statement.execute();
} catch (Exception ex) {
}
}
當我執行我收到錯誤我的java代碼是
java.sql.SQLException: Invalid column type
at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:8761)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8259)
at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:9012)
at oracle.jdbc.driver.OracleCallableStatement.setObject(OracleCallableStatement.java:4983)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setObject(OraclePreparedStatementWrapper.java:230)
我缺少什麼?!
感謝您的幫助,提前
SQL包類型麻煩你的程序似乎並沒有接受一個整數作爲輸入值,必須有一些比'setInt'更相關的方法。 – Berger
什麼是MAP_VARCHAR類型? – user7294900
MAP_VARCHAR是自定義類型,它將保存VARCHAR表並由VARCHAR建立索引。即項目('馬德里'):='皇家馬德里' – Hanson