java的tinyint_MySQL TINYINT(1)神秘地映射到Java类型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= 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.

解决方案

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 :-)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值