import java.sql.*;
// java TimestampTest jdbc:postgresql:database user password 
public class TimestampTest {
	public static void main(java.lang.String[] args) {
		Timestamp testTs[] = {
			Timestamp.valueOf("2002-01-10 19:30:59.10"),
			Timestamp.valueOf("2002-01-10 19:30:59.01"),
			Timestamp.valueOf("2002-01-10 19:30:59.999"),
			Timestamp.valueOf("2002-01-10 19:30:59.012345678"),
			Timestamp.valueOf("2002-01-10 19:30:59.876543210"),
			new Timestamp(System.currentTimeMillis())
		};
		try {
			Class.forName("org.postgresql.Driver");
			Connection db = DriverManager.getConnection(args[0], args[1], args[2]);
			Statement st = db.createStatement();
			st.executeUpdate("create table timestamp_test(string text, ts timestamp)");
			st.close();
			PreparedStatement pst = db.prepareStatement("insert into timestamp_test values(?, ?)");
			for (int i = 0; i < testTs.length; i++) {
				pst.setString(1, testTs[i].toString());
				pst.setTimestamp(2, testTs[i]);
				pst.executeUpdate();
				System.out.println(pst);
			}
			pst.close();
			db.close();
		} catch (Exception e) {
			System.out.println(e);
		}
	}
}