gpt4 book ai didi

java - SQL查询仅显示一个结果(第一个),但不显示所有结果

转载 作者:行者123 更新时间:2023-11-29 20:22:54 24 4
gpt4 key购买 nike

    private void search_fKeyReleased(java.awt.event.KeyEvent evt) {                                     
try {

这里有什么问题吗

        PreparedStatement pst =null;
ResultSet rst=(ResultSet) pst;
Connection con=(Connection)
DriverManager.getConnection("jdbc:mysql://localhost/iqari",
"root","");


String sql="select * from first where masaha_iqar=?";
pst=(PreparedStatement) con.prepareStatement(sql);
pst.setString(1,search_f.getText());
rst=pst.executeQuery();

在文本区域中,我得到的是结果,而不是数据库中的两个可用结果

        if (rst.next()){String add1=rst.getString("raqm_iqar");
jTextArea2.append(add1 + "\n");

System.out.format("%s",add1);
}

} catch (Exception e) {
}
TODO add your handling code here:
}

最佳答案

try {
PreparedStatement pst =null;
ResultSet rst=(ResultSet) pst;

Connection con=(Connection) DriverManager.getConnection("jdbc:mysql://localhost/iqari", "root","");
String sql="select * from first where masaha_iqar=?";
pst=(PreparedStatement) con.prepareStatement(sql);
pst.setString(1,search_f.getText());
rst=pst.executeQuery();
while (rst.next()){String add1=rst.getString("raqm_iqar");
jTextArea2.append(add1 + "\n");
System.out.format("%s",add1);
}

} catch (Exception e) {
}

关于java - SQL查询仅显示一个结果(第一个),但不显示所有结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39448117/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com