Can anybody help me with this? I have bean which connects to a db and runs a queary, i am then trying to go through the result set and add each item returned to a array list, at the moment i can add items to a array list by hard coding them in but am having trouble doing it with a loop:
Using this i method i can hard code data in and return it to where it was called but i want to do this in the while loop of:
Can anybody help me?
Code:
public List getVideo(String p1, String p2) {
ArrayList videos = new ArrayList();
videoBean v1 = new videoBean();
v1.setArtist("some artist"); // hard code the stuff here
v1.setTitle("the title");
videos.add(v1);
return videos;
}
Code:
String selectSQL = "Select artist_name, title" +
"from VideoTable" + "where category = " + CatPassed +" and price <= " + PricePassed +";";
Statement stmt0 = conn.createStatement();
ResultSet rs0 = stmt0.executeQuery(selectSQL);
//List VideoList = new ArrayList(); // use this instead i think // works if i put it as list not array list
while(rs0.next()) {
videoBean collection = new videoBean();
collection.setArtist(rs0.getString("artist_name"));
collection.setTitle(rs0.getString("title"));
System.out.println(collection.getArtist()); // testing in terminal
}
stmt0.close();
Comment