I'm stuck here. Please Help me!

I've created a feedback form which takes name, Email Id & Comments from users.
On submit button, i want to save the entered details along with the current date to the UserDetails table, so that, when admin logs in and wants to see the forms, he can see the date of post also.

Can you please guide me, how to get the system date and how to store it in database?
I'm using JSP.

Thank you!

Recommended Answers

All 2 Replies

java.util.Date newTime;
newTime = new java.util.Date(session.getLastAccessedTime());
out.println(new java.util.Date(session.getLastAccessedTime()));

Then store it by doing:

String sql1 = "Update table set lastAccessedTime = "+ newTime+";";
con = DriverManager.getConnection("jdbcdbc:laGuardia","","");
Statement stmt1 =con.createStatement();
int rs1 = stmt1.executeUpdate(sql1);

Don't use statement, use PreparedStatement. Date can be stored database table using either java.sql.Date (only for dates) or java.sql.Timestamp (for date along with time). Read the JDBC tutorials for more details.

Also each SQL implementation (i.e. each database) has it's own specific way of generating the current date, so if you know you are going to stick to one implementation, you can make use of that feature. For e.g. with Oracle, it's sysdate. insert into mytable(name, lastAccessed) values('sos', sysdate);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.