dateFormat的错误= new SimpleDateFormat(“dd / MM / YYYY”)。parse(G);表明找不到解析(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);
}
答案 0 :(得分:0)
SimpleDateFormat.parse()
需要一个String,而不是Date。
SimpleDateFormat.fomat()
采用日期对象。