I have this part of a class that outputs fake data in my Tomcat 4.17 container.
Now I want to substitute the fake data for real data that fetches the field value of lastname records from the Oracle database, but not sure how?
Is this in the right direction?
Now I want to substitute the fake data for real data that fetches the field value of lastname records from the Oracle database, but not sure how?
Code:
public static final int INIT_SIZE = 32; private String[] strs = null; public MyContentGenerator() { strs = new String[INIT_SIZE]; for (int i=0; i<INIT_SIZE; i++) { //need to change this next line and put database part here String str = new String("FakeData"+i); strs[i] = str; } } public int getTotal() { return strs.length; } public ArrayList getContent(int stratIndex, int endIndex) { // there is no protecttion of out of bounds ArrayList result = new ArrayList(); for (int i=stratIndex; i<endIndex && i<strs.length; i++) { result.add(strs[i]); } return result; }
Code:
//Database connection to Oracle 9i here.... Statement stmt = connection.createStatement(); ResultSet results = stmt.executeQuery("SELECT * from user"); public static final int INIT_SIZE = 32; private String[] strs = null; public MyContentGenerator() { strs = new String[INIT_SIZE]; for (int i=0; i<INIT_SIZE; i++) { while(results.next()) { String str = results.getString("lastname"); } strs[i] = str; } } public int getTotal() { return strs.length; } public ArrayList getContent(int stratIndex, int endIndex) { ArrayList result = new ArrayList(); for (int i=stratIndex; i<endIndex && i<strs.length; i++) { result.add(strs[i]); } return result; }
Comment