Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL TINYINT(1) mysteriously mapped to Java type Integer

I'm stuck in a huge and old project (j2sdk 1.4.2, Tomcat 4.1.29, MySQL 5.0.51a) that I need to install a new development environment for at work.

I've got a MySQL DB that is accessed by my Tomcat, which treats request from my Java application. In that DB, some tables contain boolean values that are needed by my application.

So, in the application, a prepared statement is made, parameters are added to it, then the request is launched and the result set of this request is stored inside of a custom SQLResult object (that is part of a custom framework made by my company, can't do anything 'bout that - though, it is quite similar to a classic java.sql.ResultSet object).

Here's the problem: when the java application request some data that are stored in the DB as TINYINT(1), those data are returned to the java application as java.lang.Integer, not java.lang.Boolean, as I would like to.

Note: the JDBC connector version used by the Tomcat server is mysql-connector-java-3.0.11-stable.

What I tested so far (without result):

  • upgrade/downgrade the MySQL connector
  • added tinyInt1isBit=<true/1> as the end of my connection string
  • upgrade/downgrade the MySQL DB, always with the same data dump I have been given along the source code
  • plenty other things I couldn't even remember, because I tested so much things :-/

I'm pretty sure now that the problem comes from the MySQL JDBC connector used by the Tomcat server. Thus, when I changed the version of the connector, nothing else was working anymore (meaning, couldn't even connect a user).

Any ideas?

EDIT: I forgot to precise that, in another part of the java application, request for data stored as DECIMAL are returned as java.lang.String! This is also a major problem I have to solve, but I think the two are linked to the same cause.

like image 479
TheFrenchieCake Avatar asked Jul 08 '26 13:07

TheFrenchieCake


1 Answers

From Connector/J documentation

MySQL Type Name: TINYINT

Return value of GetColumnClassName: TINYINT

Returned as Java Class: java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.

Please note: or java.lang.Integer if not. Check the property tinyInt1isBit and possibly change it.

If you already did it try to restart the mysql server.

like image 99
Davide Lorenzo MARINO Avatar answered Jul 11 '26 11:07

Davide Lorenzo MARINO