can not insert time into Ms access
hi guys
i need your help
i already succeeded to insert normal string values (message, sender name, etc) into the database
however i also need to insert time of the message
it seems so simple, but it can't insert
i tried every possible way, but in vain
here is code :
String insert="INSERT INTO board( name,message, subj_id, time) VALUES (?,?,?,?) ";
long time=System.currentTimeMillis();
String Time = Long.toString(time);
pstmt = con.prepareStatement(insert);
pstmt.setString(1, name);
pstmt.setString(2, message);
pstmt.setInt(3, subj_id);
pstmt.setString(4,Time);
}
pstmt.executeUpdate();
pstmt.close();
any one has a better idea
by the way i also tried psmt.setTime(4, time)
where time is in time format.
please help me with this.
thank you in advance
cheers :)
[931 byte] By [
yilmazay] at [2007-9-26 2:28:26]

i know it may sound too basic for you, but i don't know how to get the current time
i tried a lot of ways for that e.g: getTime(), getDate()
everytime i got compilation errors.
Briefly how to get time ?
in your post you suggest using the following :
**************
java.sql.Timestamp t = new java.sql.Timestamp(time);
pstmt.setTimestamp(4,t);
****************
but how to define time?
thanks for your concern
why don't you use the database date/time value? this ensures date consistency and correctness for all users entering values into the database. Every users date/time will be different and may even be erroneous. The only problem to be aware of the solution mentioned is that the function to get the current date/time out of the DB is unique for each database, thus reducing portability. Anywho, my suggestion is below:
String insert="INSERT INTO board( name,message, subj_id, time) VALUES (?,?,?,XXXX) ";
where XXXX represents the database date/time:
Oracle = SYSDATE
M$Acces = NOW
Others=check your DB documentation
Jamie