Jump to content

[4.0.2] problem in getting Integer value from DB


mtassinari

Recommended Posts

Hi everybody,

I'm facing a very strange problem while trying to pull some data from our database to a report for printing.

This database (MySQL 5.1.42 on Windows 7) contains some medical data, like the height of a person in centimeters, which is stored as a tinyint unsigned. I've created a report using iReport, which correctly recognize the field as Integer, but when the report gets printed I get a wrong result, in fact the value on the database il 165 and the value printed is -91.

I've checked the value on the DB, and it is correct, so it seems to be JasperReports which prints it wrong. I've also noticed that if I manually set the field as String, it is printed correctly.

What could be causing the problem? If possible, I'd like to preserve the correct field type in all the report...



Post Edited by mtassinari at 05/26/2011 09:08
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

 Hi,

I can't verify and I'm not sure but I  know that TINYINT is stored on 1 byte so their value can go from -128 to 127 or from 0 to 255.

 

Supposition:

127+38 = 165 unsigned

127+38 = -91 signed

 

I think the problem must come from UNSIGNED and SIGNED TINYINTS, the bits are not read in the same manner. See if you can force that property to UNSIGNED somewhere in mysql.

 

Link to comment
Share on other sites

I'm not sure that I have understood what you suggest: as I said, the fields on the database are already properly defined as TINYINT UNSIGNED, as stated in my first post...

Are you suggesting to change the query, somehow, or to change the database structure? 'Cause the structure is already correct in my opinion... So I would say this is a JasperReports' bug, if it cannot read the data correctly.

Link to comment
Share on other sites

  • 2 months later...

I just updated to the latest version, but still I can't get my unsigned tinyint fields printed correctly, jasperReports still reads them as signed.

 

Also, the data type declared in the report is java.lang.Integer, so it should have a range much wider than -128~127 or 0~255...

 

Can somebody help me? As I said, the database structure itself is correct, so it cannot and will not be changed.

Link to comment
Share on other sites

I will try that, but I'm wondering, why if I set the field type to integer for an unsigned tinyint on the database, I get that wrong result? Shouldn't the integer type go up to about 2^31?

Anyway, for now I have solved setting a data type of String for those fields that were giving the error.



Post Edited by mtassinari at 08/05/2011 13:38
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...