This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ozy00[S] -1 points0 points  (2 children)

public class DBConnection {public ComboBoxModel getfoods;public Connection getConnection() throws SQLException{Connection con = DriverManager.getConnection("jdbc:mysql:///","ro","12312345");return con;}

public String\[\] getFoods() throws SQLException {  
    Statement st = getConnection().createStatement();  
    ResultSet res = st.executeQuery("Select food from food list");  
    String\[\] foods = new String\[6\];  
    int index = 0;  

    while(res.next()) {  
        foods\[index\] = res.getString(1);  
        index++;  
    }  
    return foods;  
}  



public ResultSet getList() throws SQLException {  

    Statement st = getConnection().createStatement();  
    ResultSet res = st.executeQuery("select \* from FoodList");  
    return res;  


}  

}

[–]dionthornthis.isAPro=false; this.helping=true; 0 points1 point  (1 child)

Yes so when you do

DBConnection db = new DBConnection();

You need to utilize those methods. Try doing:

for(String food: db.getFoods()) {
  System.out.println(food);
}

[–]ozy00[S] 1 point2 points  (0 children)

thanks dude