2 Replies - 322 Views - Last Post: 18 November 2012 - 10:08 AM Rate Topic: -----

#1 justin_k  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 28-May 12

Getting Data from DB to arraylist

Posted 18 November 2012 - 08:43 AM

Hello guys, I'm having some trouble with getting data from a MySQL table, to an arraylist. It's inside a web application, an Accounts object makes the connection and uses the preparedstatement and such. I've scoured the internet looking to find how to accomplish this but I can't make much sense of it. Any suggestions?
package Business;

import java.sql.*;
import java.util.ArrayList;

/**
 * @author Justin
 */
public class Accounts {
    
    String acctID;
    String custID;
    String type;
    double balance;
    
    public Accounts(){
        acctID = "";
        custID = "";
        type = "";
        balance = 0;
    }
    
    public Accounts(String c, String i, String t, double B)/>{
        acctID = c;
        custID = i;
        type = t;
        balance = b;
    }
    
   public void setAcctID(String c){acctID = c;}
   public String getAcctID() {return acctID;} 
    
   public void setCustID(String i){custID = i;}
   public String getCustID() {return custID;}
   
   public void setType(String t){type = t;}
   public String getType() {return type;}
   
   public void setBalance(double B)/>{balance = b;}
   public double getBalance() {return balance;}

    public boolean getAccountsList() {
       boolean a = false;
       String Url="jdbc:mysql://localhost:3306/chattbank";
       String dbId="root";
       String dbPass="root"; 
       
        try {
            Class.forName("core.log.jdbc.driver.MysqlDriver");
            Connection connection = DriverManager.getConnection
            (Url,dbId ,dbPass );			
            Statement statement = connection.createStatement();
            String cmd = "select * from accounts where cID = " + getCustID();
            ResultSet rs = statement.executeQuery(cmd);	
            ArrayList<String> result = new ArrayList<String>();
            while(rs.next());
            connection.close();
        }
       catch(Exception ex){
            System.out.println(ex);
            return false;
        }
        
     return a;
    }
}



Is This A Good Question/Topic? 0
  • +

Replies To: Getting Data from DB to arraylist

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2775
  • View blog
  • Posts: 11,736
  • Joined: 20-September 08

Re: Getting Data from DB to arraylist

Posted 18 November 2012 - 09:17 AM

http://technojeeves....-to-nested-list
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: Getting Data from DB to arraylist

Posted 18 November 2012 - 10:08 AM

http://www.dreaminco...snippet6437.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1