--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To view this discussion on the web visit https://groups.google.com/d/msg/h2-database/-/bbh98dYZrUMJ.
To post to this group, send email to h2-da...@googlegroups.com.
To unsubscribe from this group, send email to h2-database...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/h2-database?hl=en.
> Hmm, still not quite understanding what you want to do.
I'm trying to find a very generic way of dealing with the situation I
described. I'm doing this, because I'm developing jOOQ (www.jooq.org),
a product similar to JaQu. I keep running into corner-case situations
of bind values with unknown type like this one with
- DB2, Derby (very often)
- HSQLDB, H2 (some times)
- Ingres, Sybase SQL Anywhere (very rarely)
I have never encountered a similar problem with
- MySQL, Oracle, Postgres, SQLite, SQL Server, Sybase ASE
That's why I was playing around with H2's data type "OTHER". As I
said, casting to "OTHER" might not be the most appropriate solution.
I'll find a way, don't worry. This user group thread here was intended
to indicate and discuss the glitch I observed when serialising /
deserialising "10" as "OTHER", which I don't think is correct
> If you don't know the type of the bind value, you should just use setObject().
> H2 has a lot of internal convert logic to handle converting it to the
> correct type.
You're correct when it comes to simple queries, like "select ?". Since
I'm looking for a stable, generic solution though, I'm afraid I always
have to cast to some type. e.g. as for this query "(select ? \"y\"
from dual) union (select ? \"y\" from dual)"
For your reference, other corner-cases I have previously reported were
these ones:
http://code.google.com/p/h2database/issues/detail?id=329
http://code.google.com/p/h2database/issues/detail?id=330
http://code.google.com/p/h2database/issues/detail?id=331
Regards,
Lukas
PreparedStatement s = conn.prepareStatement("select cast(? as other)");
s.setObject(1, "10");
This sets the value as a String, the same as:
PreparedStatement s = conn.prepareStatement("select cast('10' as other)");
What you probably want is:
PreparedStatement s = conn.prepareStatement("select cast(? as other)");
s.setObject(1, "10", Types.OTHER);
or simpler:
PreparedStatement s = conn.prepareStatement("select ?");
s.setObject(1, "10", Types.OTHER);
Regards,
Thomas
> What you probably want is:
>
> PreparedStatement s = conn.prepareStatement("select cast(? as other)");
> s.setObject(1, "10", Types.OTHER);
>
> or simpler:
>
> PreparedStatement s = conn.prepareStatement("select ?");
> s.setObject(1, "10", Types.OTHER);
That looks interesting. I'll check that.
Thanks!
Lukas
> What you probably want is:
>
> PreparedStatement s = conn.prepareStatement("select cast(? as other)");
> s.setObject(1, "10", Types.OTHER);
Thank you very much!