Problem in using Timestamp from java.sql.*

AOA

i have declared a variable

private Timestamp entryDate =new Timestamp(8);

while using it in my application. it inserts similar time stamp in database , like

01/01/1970 5:00:00 AM

How to get current time from it and how to insert it in databse.

[352 byte] By [@tifa] at [2007-10-3 3:05:30]
# 1

> AOA

> i have declared a variable

> > private Timestamp entryDate = new Timestamp(8);

>

Why? What does that 8 mean to you? Did you read the docs to see what it means to Timestamp?

>

> while using it in my application. it inserts similar

> time stamp in database , like

> 01/01/1970 5:00:00 AM

> How to get current time from it and how to insert it

> in databse.

Did you read the docs for Timestamp? There's a constructor and/or a set method that takes a Date or a number of millis. You can get the current time in millis with System.currentTimeMillis. (I think that's the method name. Look at System's docs.)

As far as inserting it, you'll do something like this: TimeStamp ts = ...;

Connection con = DriverManager.getConection(...);

PreparedStatement ps = con.prepareStatement("insert into foo (bar) values (?)");

ps.setTimestamp(1, ts);

ps.executeUpdate();

Google for jdbc tutorial for more details.

jverda at 2007-7-14 20:55:36 > top of Java-index,Java Essentials,New To Java...