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