Thread: '{ CALL put_umc_domain_attr (?, ?, ?)}' Can't be parsed In CallableStatement
HI ,
- JDBC driver build number : 407-503
- Server version : 8.1.4
- Exact error message and stacktrace
Caused by: org.postgresql.util.PSQLException: 不正确的函数或过程在偏移处2溢出。
at org.postgresql.jdbc2.AbstractJdbc2Statement.modifyJdbcCall(AbstractJdbc2Statement.java:2314)
at org.postgresql.jdbc2.AbstractJdbc2Statement.<init>(AbstractJdbc2Statement.java:136)
at org.postgresql.jdbc3.AbstractJdbc3Statement.<init>(AbstractJdbc3Statement.java:40)
at org.postgresql.jdbc3.Jdbc3Statement.<init>(Jdbc3Statement.java:30)
at org.postgresql.jdbc3.Jdbc3PreparedStatement.<init>(Jdbc3PreparedStatement.java:23)
at org.postgresql.jdbc3.Jdbc3CallableStatement.<init>(Jdbc3CallableStatement.java:20)
at org.postgresql.jdbc3.Jdbc3Connection.prepareCall(Jdbc3Connection.java:44)
at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareCall(AbstractJdbc3Connection.java:308)
at org.postgresql.jdbc2.AbstractJdbc2Statement.modifyJdbcCall(AbstractJdbc2Statement.java:2314)
at org.postgresql.jdbc2.AbstractJdbc2Statement.<init>(AbstractJdbc2Statement.java:136)
at org.postgresql.jdbc3.AbstractJdbc3Statement.<init>(AbstractJdbc3Statement.java:40)
at org.postgresql.jdbc3.Jdbc3Statement.<init>(Jdbc3Statement.java:30)
at org.postgresql.jdbc3.Jdbc3PreparedStatement.<init>(Jdbc3PreparedStatement.java:23)
at org.postgresql.jdbc3.Jdbc3CallableStatement.<init>(Jdbc3CallableStatement.java:20)
at org.postgresql.jdbc3.Jdbc3Connection.prepareCall(Jdbc3Connection.java:44)
at org.postgresql.jdbc3.AbstractJdbc3Connection.prepareCall(AbstractJdbc3Connection.java:308)
- What you were doing, ideally in code form
The sql is '{ CALL put_umc_domain_attr (?, ?, ?)}'. Where I change the sql to '{ call put_umc_domain_attr (?, ?, ?)}', it will be okay.
Here is my code:
int id = getId(entityId);
CallableStatement cstmt = null;
Connection conn = getConnection();
try {
cstmt = conn.prepareCall(sqls[SQL_PUT_ATTRIBUTE]);
Iterator names = parameters.getNames();
while (names.hasNext()) {
String name = (String) names.next();
String value = parameters.getString(name);
cstmt.setInt(1, id);
cstmt.setString(2, name);
cstmt.setString(3, value);
CallableStatement cstmt = null;
Connection conn = getConnection();
try {
cstmt = conn.prepareCall(sqls[SQL_PUT_ATTRIBUTE]);
Iterator names = parameters.getNames();
while (names.hasNext()) {
String name = (String) names.next();
String value = parameters.getString(name);
cstmt.setInt(1, id);
cstmt.setString(2, name);
cstmt.setString(3, value);
cstmt.addBatch();
}
}
cstmt.executeBatch();
}
catch (SQLException e) {
throw new AttributeException("set_attribute", e.getMessage(), e);
}
finally {
Jeton.close(cstmt);
Jeton.close(conn);
}
}
catch (SQLException e) {
throw new AttributeException("set_attribute", e.getMessage(), e);
}
finally {
Jeton.close(cstmt);
Jeton.close(conn);
}
I found the codes in class AbstractJdbc2Statement method modifyJdbcCall :
case 2: // After {, looking for ? or =, skipping whitespace
if (ch == '?')
{
outParmBeforeFunc = isFunction = true; // { ? = call ... } -- function with one out parameter
++i;
++state;
}
else if (ch == 'c') // I think here may be change to " ch == 'c' || ch == 'C'"
{ // { call ... } -- proc with no out parameters
state += 3; // Don't increase 'i'
}
else if (Character.isWhitespace(ch))
{
++i;
}
else
{
// "{ foo ...", doesn't make sense, complain.
syntaxError = true;
}
break;
if (ch == '?')
{
outParmBeforeFunc = isFunction = true; // { ? = call ... } -- function with one out parameter
++i;
++state;
}
else if (ch == 'c') // I think here may be change to " ch == 'c' || ch == 'C'"
{ // { call ... } -- proc with no out parameters
state += 3; // Don't increase 'i'
}
else if (Character.isWhitespace(ch))
{
++i;
}
else
{
// "{ foo ...", doesn't make sense, complain.
syntaxError = true;
}
break;
Fengyun