Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling a procedure in postgresql using JDBC

843859Sep 10 2005 — edited Oct 5 2005
Hai,

I am using POSTGRESQL 8.0.3 and Java 1.5.

I wrote a follwing procedure in POSTGRESQL. When I tried to call this procedure using JAVA I am getting the following exception.
Exception in thread "main" java.sql.SQLException: ERROR: syntax error at or near "$1"
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:1471)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1256)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:175)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:389)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:330)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:240)
        at ShowSurabhi2.main(ShowSurabhi2.java:44)
Code Snippet to call the procedure
Class.forName("org.postgresql.Driver");
dbcon = DriverManager.getConnection(loginUrl, loginUser, loginPasswd);
CallableStatement cs=dbcon.prepareCall("{call proc1()}");
cs.execute();
ResultSet rs = (ResultSet)cs.getObject(1);
// Iterate through each row of rs
                while (rs.next())
                {
                   id = rs.getInt(1);
                   name=rs.getString(2);
                }
Procedure in POSTGRESQL named, proc1
declare tt numeric;
begin
select max(id) into tt from test
tt = tt + 1;
ret tt;
end;
Regards
ackumar
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2005
Added on Sep 10 2005
5 comments
486 views