【发布时间】:2014-07-25 21:35:14
【问题描述】:
我正在解决需要从数据库中获取数据然后填充到 jtable 中的问题。我正在使用带有类似语句的查询。问题是当查询与一条记录匹配时,我无法在表中看到任何记录。这是我的代码。
ResultSet rs=null;
String customer_name = null;
System.out.println("In the verfiy login");
try {
Connect_MYSQL object = new Connect_MYSQL();
conn = object.getConnection();
} catch (Exception e) {
System.out.println("Error while getting connection");
}
try {
Statement statement = (Statement) conn.createStatement();
String Query = "Select * from login where username like'%"+ name+"%' or usertype like'%"+name+"%'";
System.out.println(Query);
rs = statement.executeQuery(Query);
if (rs.next()) {
System.out.println("INsie Rs");
return rs;
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
return rs;
以及我在 JTABLE 中的使用方式
DataBase_Work object=new DataBase_Work();
ResultSet rs2=object.Search_User(name);
String namee=rs2.getString("username");
System.out.println(namee+"User name");
if(rs2==null)
{
JOptionPane.showMessageDialog(null, "No Record Found Against the value", " Not Record Found", JOptionPane.ERROR_MESSAGE);
}
else
{
Show_all_User.setModel(DbUtils.resultSetToTableModel(rs2));
}
【问题讨论】:
-
A
ResultSet是一系列(或“集合”)结果,您需要迭代ResultSet以获取每一行。查看Retrieving and Modifying Values from Result Sets了解更多详情
标签: java mysql sql swing jtable