I'm making some reports in java which then get added to a jTable after execution of an sql query. However, I have a date format in my table and I can't work out how to convert between the java sql date and java util date. I've tried a few options but I always get this error:
java.sql.SQLSyntaxErrorException: Syntax error: Encountered "DATE" at line 1, column 28.
This is what my statement code looks like:
public void ordersReport() {
// if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == 1) {
String sql = "SELECT * FROM ORDERS ORDER DATE ASC, TIME ASC";
try {
DefaultTableModel model = (DefaultTableModel) ordTbl.getModel();
boolean t = model.isCellEditable(1, 1);
System.out.println(t);
rs = stmt.executeQuery(sql);
while (rs.next()) {
int ordId = rs.getInt("ORDERID");
String name = rs.getString("NAME");
String surname = rs.getString("SURNAME");
String items = rs.getString("ITEMS");
float cost = rs.getFloat("COST");
boolean priority = rs.getBoolean("PRIORITY");
String status = rs.getString("STATUS");
java.sql.Date date = rs.getDate("NAME");
Time time = rs.getTime("TIME");
int empId = rs.getInt("EMPLOYEEID");
model.addRow(new Object[]{ordId, name, surname, items, cost, priority, status, date, time, empId});
}
} catch (SQLException ex) {
Logger.getLogger(OwnerDashboard.class.getName()).log(Level.SEVERE, null, ex);
}