3

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.

3
  • 2
    You say "returned to the Java application", but if you're not using a standard ResultSet, it sounds like your custom code is accurately identifying the TINYINT column and treating it as a numeric type. Commented Nov 20, 2015 at 11:13
  • sounds you will need to make a workaround helper class for this cases... Commented Nov 20, 2015 at 11:15
  • @Jordi Castilla: unfortunately, I can't add any code yet, as this code should be running correctly (as it has been running already in a production environment for several years). My goal is, for now, to re-create a stable dev environment, with everything running as smoothly as possible, and without modifying any code. That's why I think the connector may be what causes the bug. But I can't figure out why :-/ Commented Nov 20, 2015 at 13:12

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response :-) but I already checked that, twice actually; the MySQL DB I use has not been particularly configured in any way, so the tinyInt1isBit should already be set to true; anyway I tried to set it manually, without any change observed.
0

So, after a complete week of work, I managed to found the solution. Beware, that was kind of stupid.

I was right when I thought the MySQL connector was the source of my problems. I decided to retry everything I tried until today to solve the situation, and so I slightly upgraded the connector (from v3.0.11 to v3.1.14). Then I re-launched the problematic DB requests and noticed an ERROR log I didn't see before in my Tomcat logs: the DB name specified was not correct (something like myDB\?autoReconnect=true...). Indeed, a \ had been wrongfully inserted before the connection arguments part.

I removed the guilty \ from the connection string, relaunched my Tomcat, and... tadaaa! My problems were solved!

However, I did test with the old MySQL connector (v3.0.11) and it still returns TINYINT(1) as java.lang.Integer and DECIMAL as java.lang.String. So I guess the client upgraded its MySQL connector on its production Tomcat without warning me.

Anyway, thank you all for your suggestions. Guess I'll read server logs more carefully when I debug in the future :-)

1 Comment

What you observed makes sense according to the documentation. The tinyInt1isBit property was added in v3.0.16 of the connector.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.