Posts

Showing posts with the label Databse

Why Time gets truncated with ResutSet getDate() function.

Recently I stuck in an issue on populating date from stored procedure. I am reading a date from a resultset using rs.getDate(), storing in a java.util.Date instance variable and displaying on the screen. Java.util.Date  mydate = rs.getDate(1); Output is only date while time is truncated.  But why …! That confused me a lot. So I google it. Spending lot of time in reading blogs, oracle docs and trying different things on oracle server like checking  NLS_DATE_FORMAT, I am not able to get the time. Next I come across a Timestamp thing in Resultset class. Rs.getTimestamp (int colIndex) When I use it, I immediately get the time.  Now, the important question, why the resultset function getDate() does not return the Time. Now my search is preety narrow. What I found is :- In java, we have java.util.Date for java.sq.Date . So functionalities available in sql.Date are also available in util.Date. But there is one difference, sql.Date stores only Date and not Time ...

Generate Java POJO and Hibernate XML from database tables

Today we have frameworks to persist java objects to database without writing DAO's and hibernate is one which is widely used. But for nascent developers, creating its mapping to database tables is still difficult. Recently I come across a way to generate Java  POJO and hibernate mapping XML  from database tables  using a Jboss Hibernate Tools. Its as easy as a click  and magic, mapping XML is generated and corresponding POJO 's are generated. Listed down the steps :- 1. Install the hibernate-tools jar using Eclipse's Install New software, selecting URL from http://www.jboss.org/tools/download.html depending upon the eclipse version. 2. Click on [File -> New -> Other -> Hibernate -> Hibernate Configuration File] and create a cfg file. The following properties should be specified : jdbc url , username, password, DB schema, driver class and dialect. 3. Click on [File -> New -> Other -> Hibernate -> Hibernate Console Configuration ] and crea...