无法执行程序

问题描述 投票:0回答:1

我尝试通过指定两个输入参数来调用该过程,但它不起作用。

String query = "CALL balance_change(?, ?)";
        
PreparedStatement ps = connection.prepareCall(query);
        
ps.setString(1, "Bob");
ps.setDouble(2, 333);
        
ps.execute();
        
System.out.println();
        
Statement statement = connection.createStatement();
        
ResultSet rs = statement.executeQuery("SELECT * FROM accounts WHERE name="+"Bob");
        
while (rs.next()) {
    System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getDouble(3));
}

错误:

Exception in thread "main" org.postgresql.util.PSQLException: ERROR: procedure balance_change(character varying, double precision) does not exist
  Hint: A procedure with the given name and argument types was not found. Perhaps you should add explicit type conversions.

sql postgresql jdbc procedure
1个回答
0
投票

您定义了将

numeric
作为第二个参数的过程。但是您使用
setDouble
作为第二个参数,这会引发引用的异常。

Postgres 函数类型解析(包括过程)不会接受

double precision
numeric
输入(没有显式转换),因为只有一个为
double precision
numeric
注册的“赋值”转换。这些是可接受的输入:

CALL balance_change('bla', numeric '123');  -- type `numeric`
CALL balance_change('bla', integer '123');  -- integer types (implicit cast)
CALL balance_change('bla', '123');          -- string literal
CALL balance_change('bla', 123);            -- numeric literal

小提琴

© www.soinside.com 2019 - 2024. All rights reserved.