日期:2014-05-20 浏览次数:20893 次
try { con=DriverManager.getConnection("jdbc:MySQL://127.0.0.1:3306/Phone_Contacts", "root","fzg125009"); if(radio_name.isSelected()) { pre=con.prepareStatement("SELECT DISTINCT * FROM Contact WHERE name Like '"+field_name.getText()+"%'"); } else if(radio_phone.isSelected()) { pre=con.prepareStatement("SELECT DISTINCT * FROM Contact WHERE mobile Like '"+field_phone.getText()+"%'"); } rs=pre.executeQuery(); row=new CachedRowSetImpl(); row.populate(rs); if(row.wasNull())//这个不能被执行,所以这样检测不可以 { text.append("Sorry,无此记录!\n"); } con.close(); while(row.next()) { text.append(row.getString(1)+"\t"); text.append(row.getString(2)+"\n"); } } catch (SQLException error) { System.out.println("error!"); }