Postgres DBMS 내에 저장 프로 시저와이 프로 시저를 호출하는 Java 함수를 만들었습니다. 여기 PostgreSQL 저장 프로 시저가 작동하지 않습니다.
CREATE OR REPLACE FUNCTION getlastfournisseurid(OUT lastid integer)
RETURNS integer AS
$BODY$
begin
select last_value into lastid from fournisseur_fournisseurid_seq ;
end;
$BODY$
LANGUAGE plpgsql;
함수 코드입니다 : 여기
org.postgresql.util.PSQLException: L'indice de la colonne est hors limite : 1, nombre de colonnes : 0.
at org.postgresql.core.v3.SimpleParameterList.registerOutParameter(SimpleParameterList.java:49)
at org.postgresql.jdbc2.AbstractJdbc2Statement.registerOutParameter(AbstractJdbc2Statement.java:1968)
at org.postgresql.jdbc3.AbstractJdbc3Statement.registerOutParameter(AbstractJdbc3Statement.java:1511)
at DAO.FournisseurDAO.getLastId(FournisseurDAO.java:192)
at CONTROLLER.FournisseurController.getLastIdInDataBase(FournisseurController.java:96)
at VIEW.FournisseurUi.spinnerProperties(FournisseurUi.java:183)
at VIEW.FournisseurUi.componentsProperties(FournisseurUi.java:139)
at VIEW.FournisseurUi.<init>(FournisseurUi.java:100)
at VIEW.FournisseurUi$2.run(FournisseurUi.java:542)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:744)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:714)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
프로 시저 코드 :
public int getLastId() {
String fournisseurLastId = "{ call getLastFournisseurId() }";
int lastid = -1 ;
// Get Connection
Connection connecte = utility.DatabaseConnection.getInstance();
try {
// Create a callableStatement
CallableStatement clblStmt = connecte.prepareCall(fournisseurLastId);
// Process query
clblStmt.registerOutParameter(1, java.sql.Types.INTEGER);
ResultSet result = clblStmt.executeQuery();
result.next();
lastid = clblStmt.getInt(1);
// close used resources
clblStmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
return -1 ;
} finally {
try {
if (connecte != null) {
connecte.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
return lastid;
}
}
정확하게 오류가 발생 했습니까? – Todd
질문에 오류가 추가되었습니다 –
SQL 명령 인터페이스 (psql 또는 pgAdmin3 등)에서 내장 프로 시저를 직접 호출하여 작동하는지 확인해 보셨습니까? – RealSkeptic