I have this working manually, but please need help creating this from a DB Connection and populating the Array with the results.
I just need help with populating "DestinationItem[]" from the SQL below
DestinationBean.java
// Manual Array works but I need this to be populated from DB using the below Query and DB Connection info.
private DestinationItem[] destinationResults = new DestinationItem[]{
new DestinationItem("58285", "Dodge Grand Caravan"),
new DestinationItem("57605", "Dodge SX 2.0"),
new DestinationItem("58265", "Chrysler 300 Touring")
};
public DestinationItem[] getdestinationResults() {
return destinationResults;
}
public class DestinationItem {
String destid;
String commdefid;
public DestinationItem(String destid, String commdefid) {
this.destid = destid;
this.commdefid = commdefid;
}
// Getter/Setter below
// END
I need to take this DB Connection Logic and populate the "DestinationItem[]" Array above and I need help.
//DBConnection
public static ArrayList<CustomerBean> getCustomer() {
try {
Class.forName("oracle.jdbc.OracleDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:oracle:thin:", "BLAH", "BLAH");
PreparedStatement ps = con.prepareStatement("select destination_id, commdef_id from BLAH.destination");
ArrayList<CustomerBean> al = new ArrayList<CustomerBean>();
ResultSet rs = ps.executeQuery();
boolean found = false;
while (rs.next()) {
CustomerBean e = new CustomerBean();
e.setDestId(rs.getString("destination_id"));
e.setDestId(rs.getString("commdef_id"));
al.add(e);
found = true;
}
rs.close();
if (found) {
return al;
} else {
return null; // no entires found
}
} catch (Exception e) {
System.out.println("Error In getCustomer() -->" + e.getMessage());
return (null);
}
}