How do I update a TIMESTAMP column of a MYSQL table with the current date and time in Java

I am trying to update a TIMESTAMP column of a MYSQL table with the current date and time in Java code.

String sqlString = "SELECT * FROM table WHERE ..." ;
        Statement st = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE ) ;
        ResultSet rs = st.executeQuery(sqlString) ;
        rs.first();
        rs.updateInt("status", STATUS_OPTED_OUT) ;
???---what would go here for a column "update_time" ?
        rs.updateRow();

Open in new window

sunnystarAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
stevengmoreauConnect With a Mentor Commented:
You need to use the ResultSet method updateTimestamp, and pass it a java.sql.Timestamp object with the current time:
rs.updateTimestamp("column", new java.sql.Timestamp(System.currentTimeMillis()));

Open in new window

0
All Courses

From novice to tech pro — start learning today.