查询数据并作为循环Java中另一个函数的输入传递

时间:2017-03-08 02:45:07

标签: java oracle oim

我正在编写一个应用程序,它需要从oracle数据库查询数据,并将每个查询的数据作为输入发送到java中的另一个函数。我不知道如何将这些查询数据作为输入传递给另一个函数。我试图使用Arraylist但仍然无法传递输入。任何帮助将不胜感激。希望收到你们所有人的意见。

    String dbuserName = "";
    String dbpassword = "";
    String url = "jdbc:oracle:thin:@//xxxxxxxxxxxxxx";
    String driverName = "oracle.jdbc.driver.OracleDriver";
    Connection conn = null;
    Session session = null;

    try{
        // Some Connection code to database here before  below code 
        Statement stmt = conn.createStatement();
        ResultSet rs = stat.executeQuery( "SELECT ..." );
        ArrayList <String[]> result = new ArrayList<String[]>();
        /*Queried data has only one column, that is useid, now need to
        send each id as input to below try/catch statement*/                
        try {
                userManager.enable(USER_LOGIN, true);
                System.out.print("\n Enabled user Successfully");                                               
        } catch (ValidationFailedException e) {
            e.printStackTrace();
            logger.severe("ValidationFailedException: " + e ");
        }

1 个答案:

答案 0 :(得分:0)

这会对你有所帮助

while (rs.next()) {              
        int i = 1;
        result.add(rs.getString(i++));
}

然后在for循环中

for(int i=0;i<result.size()-1;i++)
{
     String USER_LOGIN=result.get(i);
    userManager.enable(USER_LOGIN, true);
}
相关问题