• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to enter date object in ms access database

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how to make query for date object to enter in ms access database?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shahidrasul,
Your best bet is to use a PreparedStatement for your insert. This lets you type "stmt.setDate(javaDate)" rather than have to fiddle with date formats.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Just make use of this function to enter date into MsAccess database.
public static java.sql.Date getCurrentJavaSqlDate() {
java.util.Date today = new java.util.Date();
return new java.sql.Date(today.getTime());
}

So now when you want to make an entry of date into database just call this function and store it in for example say java.sql.Date object, and set it using the prepared statment. For example suppose ps is your prepared statement then ps.setDate(int,your date object) should set the date.

A sample code below to help understand:-


String sol= "INSERT into storage1([Items],[Spaceocc],[Date]) VALUES (?,?,?)";

ps2=con.prepareStatement(sol);


if(proceed){

ps2.setString(1,"Set");
ps2.setInt(2, 0);
java.sql.Date date = getCurrentJavaSqlDate();
ps2.setDate(3,date);

ps2.executeUpdate();
}


Hope this works.
 
Abhin Balur
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

Just make use of this function to enter date into MsAccess database.
public static java.sql.Date getCurrentJavaSqlDate() {
java.util.Date today = new java.util.Date();
return new java.sql.Date(today.getTime());
}

So now when you want to make an entry of date into database just call this function and store it in for example say java.sql.Date object, and set it using the prepared statment. For example suppose ps is your prepared statement then ps.setDate(int,your date object) should set the date.

A sample code below to help understand:-


String sol= "INSERT into storage1([Items],[Spaceocc],[Date]) VALUES (?,?,?)";

ps2=con.prepareStatement(sol);


if(proceed){

ps2.setString(1,"Set");
ps2.setInt(2, 0);
java.sql.Date date = getCurrentJavaSqlDate();
ps2.setDate(3,date);

ps2.executeUpdate();
}


Hope this works.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic