How Do I Insert system time Into Ms Access Using Java? -


i have created simple student registration form using java(netbeans). has several columns enter students' data such regno, name, address, etc , insert button inserts data table created in ms access.it works fine.but need store time when user fills form.it means when user fills form, system time should captured , stored in table each entry(each tuple). want know how system time , insert ms access database.i found following code.but don't know how pass time captured code database.i have created field enter time in database.

calendar cal = calendar.getinstance(); java.util.date currenttime = cal.gettime(); 

this code wrote pass time table.....

ps = con.preparestatement("insert reginfo(regno,studname,address,"                + "telephone,stream,regdate,time) values(?,?,?,?,?,?,?)"); ps.setlong(6,currenttime.gettime()); 

i used code razvan. working doesn't insert time table......("system.out.println" working properly).....

 final string t1 = "hh:mm:ss";  final dateformat df = new simpledateformat(t1);  final string formattedtime = df.format(new java.util.date());  ps.setstring(7, formattedtime);  system.out.println("formattedtime "+formattedtime); 

you can use now() function in insert query:

try (connection conn = drivermanager.getconnection(connstr)) {     string sql;     sql = "insert reginfo (regno, studname, address, telephone, stream, regdatetime) " +             "values (?, ?, ?, ?, ?, now())";     try (preparedstatement ps = conn.preparestatement(sql)) {         ps.setint(1, 3);         ps.setstring(2, "gord");         ps.setstring(3, "123 main st");         ps.setstring(4, "416-555-1212");         ps.setstring(5, "standard");         ps.executeupdate();     } } catch (exception e) {     e.printstacktrace(system.err); } 

that work both jdbc-odbc (obsolete, removed java 8) , ucanaccess (more info here).

note date/time columns in access have both date , time component, don't need maintain separate columns regdate , time.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -