javaoracle-databaseoim

Query data and pass as input for another function in a loop Java


I am writing an application that required to query data from oracle database and send each queried data as input to another function in java. I am not sure how to pass those queried data as input to another function. I am trying to use Arraylist but still could not able to pass as input. Any help will be appreciated. Hope to hear from you all.

    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 ");
        }

Solution

  • This will help you

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

    Then in the for loop

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