gpt4 book ai didi

java - 耗尽结果集

转载 作者:行者123 更新时间:2023-12-02 06:19:44 25 4
gpt4 key购买 nike

我正在开发一个网上银行系统项目。我想使用 JDBC 从数据库检索数据。然而,尽管查询在 SQLPlus 中返回一行,但它显示 Exhausted 结果异常。请帮忙。代码如下:

try
{

Class.forName("oracle.jdbc.OracleDriver");

con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "hr", "XXXXXX");
String pass = 'sid';
String user = 'sid';
String accountnumber = '2345';
String sql = "select * from user_info where account_number=?";


s1 = con.prepareStatement(sql);
s1.setString(1,accountnumber);

rs1 = s1.executeQuery(sql);
rs1.next();

if(user.equals(rs1.getString("user_name")))
{
if(pass.equals(rs1.getString("password")))
{
if(accountnumber.equals(rs1.getString("account_number")))
{
new AccountInformation(accountnumber).setVisible(true);
}
else
{
JOptionPane.showMessageDialog(this, "Account Number is Incorrect");
}
}
else
{
JOptionPane.showMessageDialog(this, "Password is Incorrect");
}
}
else
{
JOptionPane.showMessageDialog(this, "User Name is Incorrect");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(this,e);
}

最佳答案

当您将 SQL 传递给 Statement#executeQuery 时,您丢弃了绑定(bind)参数 - 使用 this one来自PreparedStatement...

rs1=s1.executeQuery();
// rs1=s1.executeQuery(sql);

// check if you got a row
if (rs1.next()) {
// as before....
}

关于java - 耗尽结果集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21120038/

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