简体   繁体   中英

Using text field to retrieve date from excel

  1. The error here shows that the data type criteria mismatch
  2. Please tell how to filter the date using two text fields
  3. 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM