Обсуждение: JDBC exception, incompatible types in simple stored procedure.
Hello. I'm using this code to access a very simple stored procedure that has 1 in parameter and 1 out parameter: String url = "jdbc:postgresql://localhost/DB2"; Properties props = new Properties(); props.setProperty("user", "user"); props.setProperty("password", "blah"); Connection conn = DriverManager.getConnection(url, props); CallableStatement upperProc = conn.prepareCall("{ ? = call stub( ? ) }"); upperProc.registerOutParameter(1, Types.OTHER); upperProc.setInt(2, 2); upperProc.execute(); Object upperCased = upperProc.getObject(1); System.out.println("uppercased:" + upperCased.toString()); upperProc.close(); I'm getting the following exception: Exception in thread "main" org.postgresql.util.PSQLException: A CallableStatement function was executed and the out parameter 1 was of type java.sql.Types=-5 however type java.sql.Types=1111 was registered. I know I can register to another type but due to other restrictions I can't change the registration type. Any idea ? Thanks. -- View this message in context: http://www.nabble.com/JDBC-exception%2C-incompatible-types-in-simple-stored-procedure.-tp21494730p21494730.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
uprooter wrote: > I'm using this code to access a very simple stored procedure > that has 1 in > parameter and 1 out parameter: > String url = "jdbc:postgresql://localhost/DB2"; > Properties props = new Properties(); > props.setProperty("user", "user"); > props.setProperty("password", "blah"); > Connection conn = DriverManager.getConnection(url, props); > CallableStatement upperProc = conn.prepareCall("{ ? = call stub( ? ) }"); > upperProc.registerOutParameter(1, Types.OTHER); > upperProc.setInt(2, 2); > upperProc.execute(); > Object upperCased = upperProc.getObject(1); > System.out.println("uppercased:" + upperCased.toString()); > upperProc.close(); > > I'm getting the following exception: > Exception in thread "main" org.postgresql.util.PSQLException: A > CallableStatement function was executed and the out parameter 1 was of type > java.sql.Types=-5 however type java.sql.Types=1111 was registered. > > I know I can register to another type but due to other restrictions I can't > change the registration type. > Any idea ? Maybe you can use PreparedStatement: PreparedStatement stmt = conn.prepareStatement("SELECT stub( ? )"); stmt.setInt(1, 2); ResultSet rs = stmt.executeQuery(); rs.next(); System.out.println("uppercased: " + rs.getObject(1)); rs.close(); Yours, Laurenz Albe
Hi. This is a workaround but not a solution since I have tooling that generates the code with the CallabaleStatement for me. these tooling works fine with other databases using callabkestatemnet and doesn't have problems with them. Should I post a bug report on that ? Thanks. Albe Laurenz-2 wrote: > > uprooter wrote: >> I'm using this code to access a very simple stored procedure >> that has 1 in >> parameter and 1 out parameter: >> String url = "jdbc:postgresql://localhost/DB2"; >> Properties props = new Properties(); >> props.setProperty("user", "user"); >> props.setProperty("password", "blah"); >> Connection conn = DriverManager.getConnection(url, props); >> CallableStatement upperProc = conn.prepareCall("{ ? = call stub( >> ? ) }"); >> upperProc.registerOutParameter(1, Types.OTHER); >> upperProc.setInt(2, 2); >> upperProc.execute(); >> Object upperCased = upperProc.getObject(1); >> System.out.println("uppercased:" + upperCased.toString()); >> upperProc.close(); >> >> I'm getting the following exception: >> Exception in thread "main" org.postgresql.util.PSQLException: A >> CallableStatement function was executed and the out parameter 1 was of >> type >> java.sql.Types=-5 however type java.sql.Types=1111 was registered. >> >> I know I can register to another type but due to other restrictions I >> can't >> change the registration type. >> Any idea ? > > Maybe you can use PreparedStatement: > > PreparedStatement stmt = conn.prepareStatement("SELECT stub( ? )"); > stmt.setInt(1, 2); > ResultSet rs = stmt.executeQuery(); > rs.next(); > System.out.println("uppercased: " + rs.getObject(1)); > rs.close(); > > Yours, > Laurenz Albe > > -- > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc > > -- View this message in context: http://www.nabble.com/JDBC-exception%2C-incompatible-types-in-simple-stored-procedure.-tp21494730p21559633.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.