Hi, You could use "cast":
SELECT * FROM (SELECT CAST(? AS VARCHAR) FROM DUAL) On Thursday, November 17, 2016, Boris Granveaud <[email protected]> wrote: > Hello, > > I have a problem with the following statement: > > SELECT * FROM (SELECT ? FROM DUAL) > > it gives this error with H2 1.4.191: > > org.h2.jdbc.JdbcSQLException: Unknown data type: """?1"""; SQL statement: > SELECT * FROM (SELECT ? FROM DUAL) [50004-192] > at org.h2.message.DbException.getJdbcSQLException(DbException.java:345) > at org.h2.message.DbException.get(DbException.java:179) > at org.h2.message.DbException.get(DbException.java:155) > at org.h2.table.Table.setColumns(Table.java:425) > at org.h2.table.TableView.initColumnsAndTables(TableView.java:220) > at org.h2.table.TableView.init(TableView.java:98) > at org.h2.table.TableView.<init>(TableView.java:65) > at org.h2.table.TableView.createTempView(TableView.java:535) > at org.h2.command.Parser.readTableFilter(Parser.java:1168) > > Code to reproduce: > > PreparedStatement st = cnx.prepareStatement("SELECT * FROM (SELECT ? FROM > DUAL)"); > st.setTimestamp(1, new Timestamp(System.currentTimeMillis())); > rs = st.executeQuery(); > rs.next(); > System.out.println(rs.getObject(1)); > rs.close(); > st.close(); > > "SELECT ? FROM DUAL" works fine. > > The problems is that the type of the parameter cannot be known when the > statement is prepared so I'm not sure how the parser should deal with that. > > Boris. > > -- > 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 [email protected] > <javascript:_e(%7B%7D,'cvml','h2-database%[email protected]');> > . > To post to this group, send email to [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');>. > Visit this group at https://groups.google.com/group/h2-database. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/h2-database. For more options, visit https://groups.google.com/d/optout.
