Hello I am trying to take a multi-deminsional array[ ] [ ] (2D (if you will)) and set a varriable through a classes public setter.

    //some of the fields
    private int request_id;
    private String time_stamp;
    private int session_id;
    private int client_intf;
    private int server_intf;
    // many more...

       // Some Getters
    public int getRequest_id() { return request_id; }

    public String getTime_stamp()
    {
        return time_stamp;
    }

    public int getSession_id()
    {
        return session_id;
    }

    public int getClient_intf()
    {
        return client_intf;
    }

    public int getServer_intf()
    {
        return server_intf;
    }

    // some setters
    public void setRequest_id(int request_id)
    {
        this.request_id = request_id;
    }

    public void setTime_stamp(String time_stamp)
    {
        this.time_stamp = time_stamp;
    }

    public void setSession_id(int session_id)
    {
        this.session_id = session_id;
    }

    public void setClient_intf(int client_intf)
    {
        this.client_intf = client_intf;
    }

    public void setServer_intf(int server_intf)
    {
        this.server_intf = server_intf;
    }



    // initialize variables from array[][]
      //todo // FIXME: 2/6/2016
    public void initializeUpload(String[][] csvArray)
    {  
        for (int i = 1; i < csvArray.length; i++)
        {

            for (int j = 0; j < csvArray[i].length; j++)
            {
                setRequest_id(Integer.parseInt(csvArray[i][j]));
                setTime_stamp(csvArray[i][j]);
                setSession_id(Integer.parseInt(csvArray[i][j]));
                // I know this is setting them over and I just 
                // know how to approach this problem
                //any insight would be very much apprecitated.
                // this is just part of a larger app
            }
        }

    }

There's no sensible shortcut for this kind of thing, but the code you posted has an incorrect second loop and uses the same value for every field. Ignoring the parseInts it should look like

 for (String[] record :  csvArray) 
      setFirstField(record[0]);
     setSecondField(record[1]);
     Etc

Ps please excuse garbled code, I'm on an iPad, and this site is a nightmare to use in iOS

Edited 9 Months Ago by JamesCherrill

Also, posting the problem that you're running into would greatly help us understand and help you accomplish what you're trying to solve.

Comments
Well I posted the problem

Doogledude123, what I'm attempting to do is take a csv and place it in an array[][] and then upload that to a mySQL DB. I am using opencsv to parse the csv into the array. The problem I am still having after correcting the above mistake is a number format exception. Here is the Java for upoading the data:

 public void add() throws SQLException

    {
        try
        {


            // setup database connection
            Statement stmt;
            DBConnect conn = new DBConnect();
            stmt = conn.makeStatement();
            stmt.execute("Insert Into webfilterevents (request_id,time_stamp,session_id," + //domain is acting like keyword
                    "client_intf,server_intf,c_client_addr,s_client_addr,c_server_addr,s_server_addr,c_client_port," +
                    "s_client_port,c_server_port,s_server_port,policy_id,username,hostname,method,uri,host,domain," +
                    "c2s_content_length,s2c_content_length,s2c_content_type,ad_blocker_cookie_ident,ad_blocker_action," +
                    "web_filter_lite_reason,web_filter_lite_category,web_filter_lite_blocked,web_filter_lite_flagged," +
                    "web_filter_reason,web_filter_category,web_filter_blocked,web_filter_flagged,virus_blocker_lite_clean," +
                    "virus_blocker_lite_name,virus_blocker_clean,virus_blocker_name,url)"
                    + " Values ('"
                    + getRequest_id() + "', '"
                    + getTime_stamp() + "', '"
                    + getSession_id() + "', '"
                    + getClient_intf() + "', '"
                    + getServer_intf() + "', '"
                    + getC_client_addr() + "', '"
                    + getS_client_addr() + "', '"
                    + getC_server_addr() + "', '"
                    + getS_server_addr() + "', '"
                    + getC_client_port() + "', '"
                    + getS_client_port() + "', '"
                    + getC_server_port() + "', '"
                    + getS_server_port() + "', '"
                    + getPolicy_id() + "', '"
                    + getUsername() + "', '"
                    + getHostname() + "', '"
                    + getMethod() + "', '"
                    + getUri() + "', '"
                    + getHost() + "', '"
                    + getDomain() + "', '"
                    + getC2s_content_length() + "', '"
                    + getS2c_content_length() + "', '"
                    + getS2c_content_type() + "', '"
                    + getAd_blocker_cookie_ident() + "', '"
                    + getAd_blocker_action() + "', '"
                    + getWeb_filter_lite_reason() + "', '"
                    + getWeb_filter_lite_category() + "', '"
                    + getWeb_filter_lite_blocked() + "', '"
                    + getWeb_filter_lite_flagged() + "', '"
                    + getWeb_filter_reason() + "', '"
                    + getWeb_filter_category() + "', '"
                    + getWeb_filter_blocked() + "', '"
                    + getWeb_filter_flagged() + "', '"
                    + getVirus_blocker_lite_clean() + "', '"
                    + getVirus_blocker_lite_name() + "', '"
                    + getVirus_blocker_clean() + "', '"
                    + getVirus_blocker_name() + "', '"
                    + getUrl()
                    + "' )");

            stmt.close();
            conn.close();

        } catch (SQLException | InputMismatchException e)
        {
            System.err.println(e + "Could not insert");
        }

        System.out.println("Successfully added student to database");
        System.out.println("from Undergraduate class");

    }
This article has been dead for over six months. Start a new discussion instead.