If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > Is it above correct statement insert date in Access database table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-12-10, 05:01
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
Is it above correct statement insert date in Access database table

Code:
String sqlCommand2= "INSERT INTO Orders VALUES('1021','0021','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+OrderTotals2.getShipping()+","+OrderTotals2.getTax()+")" ;
   
//  OrderNumber, CustID,date-ordered,date-shipped,....
sttmnt1.executeUpdate(sqlCommand2);
Is it above correct statement insert date in Access database table OR this is for MySQL... I have Access and 3 tables: Customer,Orders, OrderDetail although only first populated each script execution, well?

Is it this correct order populate tables correct:Customer,Orders, OrderDetail ?

Please Tell me and for below, is it correct code?
Code:
   List lineList2 = OrderTotals2.getLineList();

        for (int i = 0; i < lineList2.size(); i++)  //lineList2.length
        {
          OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);

          String sqlCommand3= "INSERT INTO OrderDetail VALUES('1021',"+i+1+","+lineItem0.getPlantID()+","+lineItem0.getQty()+","+lineItem0.getSubtotal()+")" ;

            sttmnt2.executeUpdate(sqlCommand3);
        }

Last edited by lse123; 06-12-10 at 05:05.
Reply With Quote
  #2 (permalink)  
Old 06-25-10, 13:35
sco08y sco08y is offline
Registered User
 
Join Date: Oct 2002
Location: Baghdad, Iraq
Posts: 697
Code:
String sqlCommand2= "INSERT INTO Orders VALUES('1021','0021','"
    + new java.util.Date() +"','"
    + new java.util.Date() + "',"
    + OrderTotals2.getTotal() + ","
    + OrderTotals2.getShipping() + ","
    + OrderTotals2.getTax() + ")" ;
   
//  OrderNumber, CustID,date-ordered,date-shipped,....
sttmnt1.executeUpdate(sqlCommand2);
My Java's a little rusty, but I believe that arguments to string concatenation will be coerced to strings through the default toString method. So, that's valid Java, at least.

The real issue is whether your dates are formatted correctly to pass to Access. The default string coercion will return a human readable representation of the Java Date value, but you probably need to use a specific formatting method to return a string that Access understands as a date / time. It would help to know exactly what the column type is, since Access handles a couple of different date / time types.

IIRC, Access will take a date formatted in the local system format surrounded by hashes. So #Jan 1, 2010# would probably work as a date literal. Not sure if #Jan 1, 2010 12:30AM# would work for the time. You'll want to check the docs (search for "date literal")and then run some tests to see what the DBMS accepts.

Once you know how to format the date, Java has a number of methods to format Date objects, especially in the Calendar class. I can't link you to the docs without knowing what version of Java you're using, but Java Date and Java Calendar are helpful Google searches.
Reply With Quote
  #3 (permalink)  
Old 06-25-10, 13:52
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
go and try one format of fixed date to see if works, below?
I use java 6 update 17.

Code:
String sqlCommand2= "INSERT INTO Orders VALUES('1021','0021',
     '#Jan 1, 2010 12:30AM#',
     '#Jan 1, 2010#',"
    + OrderTotals2.getTotal() + ","
    + OrderTotals2.getShipping() + ","
    + OrderTotals2.getTax() + ")" ;
   
//  OrderNumber, CustID,date-ordered,date-shipped,....
sttmnt1.executeUpdate(sqlCommand2);
Reply With Quote
  #4 (permalink)  
Old 06-25-10, 13:58
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
Access, or more properly JET prefers dates in US format MM / DD / YYYY or MM / DD / YY. , I think it can also accept ISO date format YYYY DD MM

so you need to make certain your SQL complies with that.

To make life easier for yourself I'd recommend that you include a column list to clearly tell the SQL engine what columns you want to insert/update
I'd also check your SQL is actually valid use an appropriate debugging / break point to prove that. I often display the SQL then copy and paste it into the target SQL engines query browser and make certain it works there if I'm unsure if the SQL is correct.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #5 (permalink)  
Old 07-17-10, 18:10
lse123 lse123 is offline
Registered User
 
Join Date: May 2007
Posts: 139
May use in Access and

May use in Access and

long time = claim.getClaimDate().getTime();
java.sql.Date date = new java.sql.Date(time);

and insert var: date ???
Reply With Quote
  #6 (permalink)  
Old 08-06-10, 05:04
jeangrey0510 jeangrey0510 is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
Great! I also need this information. Thanks for sharing guys!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On