Re: Put each row into an array of strings?
Posted by: Branden Patey
Date: July 09, 2014 03:57PM

sorry I was a little too vague asking about this, I've learned about it a litte more and made some progress.

I still have a problem somewhere though- I've created a method to retrieve the data, then in the JTable I call the method as the Object[][] instead of "new Object[][]" but it's not rerieving anything when testing the program.

the retrieval method:

public Object[][] getEmployees(){
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
ResultSet rs2 = null;
String[] xsettings = null;
Object[][] userList = new Object[6][];

try {
xsettings =;
conn = DriverManager.getConnection("jdbc:mysql://"+ xsettings[0] +"/"+ xsettings[4] +"?user="+ xsettings[2] +"&password="+ xsettings[3]);
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT * FROM employees");

for (int i = 0, j = 0; j > 6 ; i++) {
userList[j++] = rs.getString("ID");
userList[j++] = rs.getString("name");
userList[j++] = rs.getString("email");
userList[j++] = rs.getString("password");
userList[j++] = rs.getString("phone");
userList[j++] = rs.getString("phone_number");

} catch (Exception ex) {
}finally {

if (rs != null) {
try {
} catch (SQLException sqlEx) { } // ignore

rs = null;

if (stmt != null) {
try {
} catch (SQLException sqlEx) { } // ignore

stmt = null;
return userList;

!~! and the beginning of the JTable looks like this: ~!~

employee_list = new JTable();
Object[][] userList = new Object[6][];
employees employees = new employees();
userList = employees.getEmployees();
employee_list.setModel(new DefaultTableModel( userList,
new String[] {
"ID", "Name", "Email", "Password", "Call?(yes/no)", "Phone Number"

Options: ReplyQuote

Written By
Re: Put each row into an array of strings?
July 09, 2014 03:57PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.