• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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
  • 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();
 
Marshal
Posts: 25804
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Marshal
Posts: 67447
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Tapas", please check your private messages for an important administrative matter. Thanks.
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic