Hi,

I looked at the Date example that comes with the mm.mysql driver, but I 
still can't get this to work.

When I run the code below, I have no errors, but I only end up with nulls 
in my table.


This is getting weird..


Thanks,


Eric


======================
import java.sql.*;
import java.util.*;
import java.util.Date;

public class mysqldatetest {

     public static void main(String[] args) {

     // Try to load the JData2_0 driver

     try  {
       //Driver drv = (Driver) 
Class.forName("JData2_0.sql.$Driver").newInstance();
       Class.forName("org.gjt.mm.mysql.Driver").newInstance();
     }
     catch (Exception e) {
         System.out.println("Cannot load the driver, reason:"+e.toString());
         System.out.println("Most likely the Java class path is incorrect.");
     }



     try {
       // Change MyDSN, myUsername and myPassword to your specific DSN
       //Connection c 
=java.sql.DriverManager.getConnection("jdbc:JDataConnect://216.17.163.114/test");
       Connection c 
=java.sql.DriverManager.getConnection("jdbc:mysql://192.168.0.12/CustomerService?user=user&password=password");
       c.setAutoCommit(true);

       Statement stmt = c.createStatement();
      stmt.executeUpdate("DROP TABLE date_test");

       stmt.executeUpdate("CREATE TABLE date_test (datefield datetime 
,datefield2 datetime )");

       PreparedStatement pStmt = c.prepareStatement("INSERT INTO date_test 
(datefield,datefield2) VALUES(datefield=?, datefield2=?)");


       // make a date type


       java.sql.Date date = new java.sql.Date(new Date().getTime());
       java.sql.Date date2 = new java.sql.Date(2002,3,22);

       Timestamp time = new Timestamp(date.getTime());
         long startDate = 1017684000000L;

       System.out.println("Date:"+ time);


        //for (int i = 0; i < 10; i++) {

             pStmt.setTimestamp( 1, new Timestamp( date2.getTime())  );
             pStmt.setTimestamp( 2, new Timestamp(startDate) );

             pStmt.executeUpdate();

        //}
             pStmt.close();




     }

     catch (Exception e) {
       System.out.println("Error connecting or reading table:"+e.getMessage());
       e.printStackTrace(System.out);
     }



     }
}










Leading Edge Marketing Inc.
250-360-2992


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to