Is it OK to pass String instances for fields of non-varchar types?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it OK to pass String instances for fields of non-varchar types?

rdgoite
Hi.

I'm working on an insert statement for a mapper which takes a
java.util.Map as a parameter. It's convenient for me to have the Map
of type <String, String> since if you're familiar with Commons
BeanUtils I'm using its describe method. This is so that I don't have
to do a lot more coding to handle instances a complex class hierarchy.
However, as I've said, all I get are String instances as values
regardless of what types the data are originally. I've actually tested
the code to be working, I just want to confirm if it's permissible and
maybe why and how.

Thanks.
Reply | Threaded
Open this post in threaded view
|

RE: Is it OK to pass String instances for fields of non-varchar types?

Poitras Christian
I think it depends on the JDBC driver more than MyBatis.
If the JDBC driver doesn't care about type conversion it's ok. MyBatis will call PreparedStatement.setString(int, String).

I don't recommend going this way since it will not be compatible with all JDBC drivers...

Christian

-----Message d'origine-----
De : [hidden email] [mailto:[hidden email]] De la part de rdgoite
Envoyé : September-03-10 11:18 PM
À : mybatis-user
Objet : Is it OK to pass String instances for fields of non-varchar types?

Hi.

I'm working on an insert statement for a mapper which takes a
java.util.Map as a parameter. It's convenient for me to have the Map
of type <String, String> since if you're familiar with Commons
BeanUtils I'm using its describe method. This is so that I don't have
to do a lot more coding to handle instances a complex class hierarchy.
However, as I've said, all I get are String instances as values
regardless of what types the data are originally. I've actually tested
the code to be working, I just want to confirm if it's permissible and
maybe why and how.

Thanks.