resultSet next()方法不返回任何值

时间:2016-04-03 10:21:41

标签: java oracle jdbc

没有弄清楚这段代码有什么问题。但当我单独运行查询时,我得到单列输出。但ResultSet next()方法没有返回任何值。请帮忙。无论如何,我总是得到空值。

package magicNumberGame;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class GetQuery {

    GetMagicNumber getMagicNumber = new GetMagicNumber();   
    String SelectQuery;
    String  query;

    public void selectQuery()
    {
        try {
            Class.forName("oracle.jdbc.driver.OracleDriver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        try{
        Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","SYSTEM","Rajak1991@");
        Statement st = con.createStatement();

        SelectQuery = "SELECT QUERY FROM MAIN_QUIZ_QUERY WHERE SERIAL_NO=15";

        ResultSet result = st.executeQuery(SelectQuery);    

        while(result.next())
        {
            query = result.getString(1);
            con.close();
        }

    }catch(SQLException e)
    {
        e.printStackTrace();
    }   
 }  

    public String getQuery()
    {
        return query;
    }

    public static void main(String[] args) {

        GetQuery g = new GetQuery();
        g.selectQuery();
        System.out.println("main method : "+ g.getQuery());//  
    }
}

0 个答案:

没有答案