The error at dateFormat = new SimpleDateFormat("dd/MM/YYYY").parse(G); shows that no method found for parse (Date)
String a=jTextField1.getText(); String b=jTextField2.getText(); Date n=new Date(); SimpleDateFormat date = new SimpleDateFormat("dd/MM/YYYY"); DefaultTableModel tm=(DefaultTableModel)jTable1.getModel(); try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con; con = DriverManager.getConnection ("jdbc:odbc:NAMT","Navi","1234"); PreparedStatement ps=con.prepareStatement( "select * from [Sheet1$] where SEVERITY='Critical' and DATE BETWEEN '"+a+"'and'"+b+"'" ); try (ResultSet rs =ps.executeQuery()) { while(rs.next()) { String B=rs.getString("NetworkElement"); String E=rs.getString("Severity"); java.util.Date G = rs.getDate("DATE"); java.util.Date dateFormat; dateFormat = new SimpleDateFormat("dd/MM/YYYY").parse(G); tm.addRow(new Object[] {B,E,G}); } } con.close(); } catch(Exception x) { System.out.println(x); }
SimpleDateFormat.parse()
expects a String, not a Date.
SimpleDateFormat.fomat()
takes a Date-Object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.