Re: [h2] Re: Cannot find symbol NUMERIC

2023-03-24 Thread Evgenij Ryazanov
With JDBC, you can call your function either with PreparedStatement or with 
CallableStatement:

try (Connection c = DriverManager.getConnection("jdbc:h2:mem:1")) {

Statement s = c.createStatement();

s.execute("CREATE ALIAS my_stored_proc AS 'BigDecimal send() { return 
BigDecimal.ONE; }'");

// With PreparedStatement

PreparedStatement ps = c.prepareStatement("CALL my_stored_proc()");

ResultSet rs = ps.executeQuery();

rs.next();

System.out.println(rs.getBigDecimal(1));

// With CallableStatement

CallableStatement cs = c.prepareCall("{? = CALL my_stored_proc()}");

cs.registerOutParameter(1, Types.NUMERIC);

cs.execute();

System.out.println(cs.getBigDecimal(1));

}

In case of callable statement you should register the output parameter 
only, because your function doesn't have any input parameters. It is also 
possible to use it without registration of output parameter, in that case 
result can be read from it in the same way as from prepared statement.

You use a wrapper over JDBC, it has a different API, but situation in the 
same. Your function doesn't have any input parameters, it means you 
shouldn't try to pass them here, hypothetically SimpleJdbcCall can be 
confused by that unexpected parameter. You can try to run it without 
parameters. But I never used that library, so I can't be sure.

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/927ea4e9-60d0-41ad-b186-95202b3bdcfan%40googlegroups.com.


Re: [h2] Re: Cannot find symbol NUMERIC

2023-03-24 Thread ELIELDO MARTINS
My code is the following:

CREATE ALIAS my_stored_proc AS '
  import java.math.BigDecimal;
  @CODE
  BigDecimal send() {
return BigDecimal.ONE;
}
';


// call the send routine to csmp
SimpleJdbcCall jdbcCall = new SimpleJdbcCall(jdbcTemplate)
.withFunctionName("my_stored_proc");

SqlParameterSource paramMap = new MapSqlParameterSource()
.addValue("id", 1);

BigDecimal result = jdbcCall.executeFunction(BigDecimal.class,
paramMap);

-
But, it is returning "null"!

Can you imagine why?

Em qui., 23 de mar. de 2023 às 21:09, Evgenij Ryazanov 
escreveu:

> Hello!
>
> The valid syntax is
>
> CREATE ALIAS MY_STORED_PROC AS '
> BigDecimal envia() {
> return BigDecimal.ONE;
> }
> ';
>
> because SQL NUMERIC data type is mapped to BigDecimal data type in Java.
>
> --
> You received this message because you are subscribed to the Google Groups
> "H2 Database" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to h2-database+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/h2-database/92fde29d-e26e-4816-b752-d7e568b971c1n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to h2-database+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/CAMbOUNTnDbbXZ36OOQpDxvAQm00jrE_d8jJF9JA5h%2BEjwVjVCQ%40mail.gmail.com.