I am trying to change the time of the server before executing the preparedStatement. The server time is EDT and I want to add 6 hours to it before using it in the preparedStatement.
Currently I am getting this error:
DateUtils cannot be resolved.
How can I fix it?
I appreciate any help.
Code:
String sql = "SELECT r.route "
+ "FROM routes AS r "
+ "JOIN arrivaltimes AS a ON a.route_id = r.route_id "
+ "JOIN stops as s on a.stop_id = s.stop_id "
+ "WHERE a.weekday = ? "
+ "AND arrivaltime BETWEEN ? - INTERVAL 2 MINUTE AND ? + INTERVAL 2 MINUTE "
+ "AND s.name = ?";
PreparedStatement preparedTime = con.prepareStatement(sql);
Date d1 = new Date();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
String serverTime = df.format(d1);
java.sql.Time time = null;
try {
time = new java.sql.Time(df.parse(serverTime).getTime());
Date newDate = DateUtils.addHours(time, 6);
} catch (ParseException e) {
e.printStackTrace();
}
As per your first comment, The import org.apache.commons cannot be resolved means that the jar commons-lang.jar is missing from your classpath. Add the jar to your class path and the import will be successful.
As per your second comment, java.util.Date belongs to rt.jar (and some other jars too). DateUtils and Date have a different package structure and available through separate jars.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With