I am developing a simple desktop Java application to retrieve newly added records from MS Access database and put those in to Mysql and I am gonna make this as a scheduled task.
I have a JButton and when i click that button, the records those created today in MS Access has to be fetched and display in to my JTable, this is the purpose.
The problem I am facing is trying to retrieve records based on current date from MS Access. I am using Java8 and using "ucanaccesss" driver for establishing connection between my application and MS Access. I get date mismatched errors.
try {
// TODO add your handling code here:
SimpleDateFormat objSDF = new SimpleDateFormat("dd-mm-yyyy");
java.util.Date dt_1 = objSDF.parse("06-12-2019");
//String date6 = objSDF.format(dt_1);
try {
Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");
String msAccDB = "C:/Users/t1/Dropbox/P2002/p2002.mdb";
String dbURL = "jdbc:ucanaccess://" + msAccDB;
DefaultTableModel model1 = new DefaultTableModel();
jTable1.setModel(model1);
model1.setColumnIdentifiers(new Object[]{"ID", "Datum", "Summe"});
Connection li = DriverManager.getConnection(dbURL);
PreparedStatement pstm = li.prepareStatement("SELECT ID,Datum,Summe FROM Bes WHERE Datum = #"+dt_1+"#");
ResultSet Rs = pstm.executeQuery();
while (Rs.next()) {
model1.addRow(new Object[]{Rs.getInt(1), Rs.getString(2), Rs.getDouble(3)});
}
li.close();
} catch (ClassNotFoundException cnfe) {
System.out.println(cnfe);
} catch (SQLException sqle) {
System.out.println(sqle);
}
} catch (ParseException ex) {
Logger.getLogger(GetRecords.class.getName()).log(Level.SEVERE, null,ex);
}***