T
teser3
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?
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++) {
String str = new String("FakeData"+i);
strs = 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);
}
return result;
}
Is this in the right direction?
Class.forName("org.gjt.mm.mysql.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://
localhost/mydbhere?user=jones&password=thepasswordhere");
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 = 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);
}
return result;
}
Now I want to substitute that for database that fetches something
called lastname records from the databse, but not sure how?
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++) {
String str = new String("FakeData"+i);
strs = 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);
}
return result;
}
Is this in the right direction?
Class.forName("org.gjt.mm.mysql.Driver");
Connection connection = DriverManager.getConnection("jdbc:mysql://
localhost/mydbhere?user=jones&password=thepasswordhere");
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 = 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);
}
return result;
}