dreampolice
Technical User
I have this part of a java program that outputs fake data.
Now I want to substitute that for database that fetches something called lastname records from the databse, but not sure how?
Is this in the right direction?
Now I want to substitute that for database that fetches something called lastname records from the databse, 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 part only 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;
}
Is this in the right direction?
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;
}