Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

data type mapping between POJO class and database data type

 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a column in a table has a data tiem like "datetime" (SQL server), should I set in my java POJO

as

private java.util.Date day;

or

private java.sql.Date day;

where "day" is the attribute maps to the column with "datetime" type.

 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj,
You can use java.util.Date to set date in your pojo
 
Raj Ohadi
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. What if the database type is "decimal", then in the POJO, should we use double or BigDecimal ? I guess it depends on the size of Decimal. Decimal can be verylarge number and in that case we better use "BigDecimal", if the size is not big, say decimal(10, 5) which has 5 digits on the left of decimal points then using "double" should be sufficient, does this make sense ?
 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj
As per Specifications we have to use double. The double data type is a double-precision 64-bit floating point. in section 4.2.3 of the Java Language Spec. For decimal values, this data type is generally the default choice.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic