简体   繁体   English

此Java错误的含义是什么

[英]What is meaning of this java error

I am trying to retrieve data from my database here this is my code, followed by the error. 我正在尝试从数据库中检索数据,这是我的代码,然后是错误。 What's going wrong? 怎么了 Any help appreciated in figuring out why it returns the error message it does. 弄清楚为什么它返回错误消息的原因可以得到任何帮助。

My code: 我的代码:

String query = "SELECT * FROM ebloodfinder.tempids";

try {
    int a = db.updateResult(query).getInt("did");
    int b = db.updateResult(query).getInt("bid");
    dor.setDid(++a);
    dor.setBid(++b);
} catch (ClassNotFoundException | SQLException ex) {
    Logger.getLogger(testForm.class.getName()).log(Level.SEVERE, null, ex);
}

jtxt_Did.setText(dor.getDid()+"");
jtxt_Did_DR.setText(dor.getBid()+"");

This exception occurs: 发生此异常:

/*  Dec 12, 2014 2:22:37 PM extra.testForm <init>
SEVERE: null
java.sql.SQLException: Before start of result set*/

You need to move the cursor to the first row and then request for the data. 您需要将光标移动到第一行,然后请求数据。

int a = 0, b = 0;

try {
    ResultSet rs = db.updateResult(query)

    if (rs.next()) { 
        a = rs.getInt("did");
        b = rs.getInt("bid");
    }
} 
catch (ClassNotFoundException | SQLException ex) {
    //blah blah
}

When you get the results in the ResultSet its cursor is at the position Before First . 当您在ResultSet中获得结果时,其光标位于Before First的位置。

Some Hint 一些提示

Say if the data starts from 1st row then the cursor will be at 0. 假设数据从第一行开始,则光标将位于0。

What you need to do is move the cursor to the First position to read data. 您需要做的是将光标移到“第一”位置以读取数据。

To do this you need to call rs.next() method and this method returns boolean . 为此,您需要调用rs.next()方法,并且此方法返回boolean If it moves to next position then true, if no more further positions are there then false. 如果移动到下一个位置,则为true;如果没有其他位置,则为false。

The same method can be used to iterate through all the rows fetched from the server. 可以使用相同的方法遍历从服务器获取的所有行。

while(rs.next()){
    //get data
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM