• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to insert Date data in Oracle database in MM/DD/YYYY HH:MM:SS format?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Through BatchSqlUpdate how to insert date data as MM/DD/YYYY HH:MM:SS?
Here is my code

String insert_Query ="insert into table ("+
"student_id,student_name,admission_date) values (?,?,?)";
BatchSqlUpdate updater = new BatchSqlUpdate(getDataSource(), insert_Query);
updater.declareParameter(new SqlParameter(Types.VARCHAR));
updater.declareParameter(new SqlParameter(Types.VARCHAR));//app_id
updater.declareParameter(new SqlParameter(Types.DATE));
updater.compile();
System.out.println("After updater");

while (rs.next()) {

System.out.println("Inside While");
Object[] values = new Object[3];
values[0] = rs.getString("student_id");
values[1] = rs.getString("student_name");

//Here arrival_time is Epoch time. e.g. value will be like '1316363322','1316377882'
Long dateTemp1 = null;
dateTemp1 = rs.getLong("admission_date");
values[2] = new java.util.Date (dateTemp1*1000);

//With SOP we are getting value as Sun Sep 18 19:52:08 IST 2011 for new java.util.Date (dateTemp1*1000);

//After the insertion into oracle database the value is only 09/18/2011
// How to get the value as 09/18/2011 19:52:08
//In Oracle the admission_date column datatype is Date


System.out.println(new java.util.Date (dateTemp1*1000));
updater.update(values);
}
updater.flush();
 
Sheriff
Posts: 27530
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tapas wrote:updater.declareParameter(new SqlParameter(Types.DATE));


Are you sure this is the correct type? Normally in SQL there are Date, Time, and Timestamp column types. Date produces the results you are seeing.
 
Tapas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

updater.declareParameter(new SqlParameter(Types.DATE));

is the correct type. It is entering Date data into Oracle db table only MM/DD/YYYY data.

I tried

updater.declareParameter(new SqlParameter(Types.TIME));

in place of above statement. Now it is working as expected. Date entered into db as MM/DD/YYYY HH:MM:SS .

Thanks,
Tapas



 
Ranch Hand
Posts: 174
Java ME Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Make sure you're inserting correct data format (for example, timestamp for datetime)
2) Make sure that in database this date column is with correct data type for holding both date and time.
 
Sheriff
Posts: 67694
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Tapas", please check your private messages for an important administrative matter. Thanks.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic