小编Mor*_*yit的帖子

如何运行Resultset.next()两次?

我有这个方法来获取一串行并打印它们.

另外,我要做while(Resultset.next())两次.第一个是获取行数,第二个是打印字符串.但是当方法第一次运行时Resultset.next(),方法会跳过第二次Resultset.next().

public static String[] gett() throws ClassNotFoundException, SQLException{

    // this for get conneced to the database .......................

    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE","hr","111"); 
    Statement st = conn.createStatement();
    ResultSet re = st.executeQuery("select location_id from DEPARTMENTS");

    // Ok , now i have the ResultSet ...

    // the num_row it's counter to get number of rows
    int num_row = 0;

    // this Arrar to store String values
    String[] n = new String[num_row];

    // this is the first …
Run Code Online (Sandbox Code Playgroud)

java sql oracle jdbc resultset

3
推荐指数
1
解决办法
5328
查看次数

标签 统计

java ×1

jdbc ×1

oracle ×1

resultset ×1

sql ×1