Hi guys, I'm trying to create an array with the length according to the number of rows in my database. So here is my code. I getting "array out of bound".
import java.sql.*;
import javax.swing.*;
public class prg extends javax.swing.JFrame(){
String nameC = "HDB";
String nameCC = "";
int count=0;
public BookPgr(String theUser, int theCount) {
initComponents();
connect();
count = theCount;
}
Info[] List = new Info[count];
public void connect() {
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection("jdbc:odbc:DB");
st = con.createStatement();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, "Error connection to DB\n" + ex.getMessage());
}
}
public void StoreinArray() {
try {
String SQLCMD = "Select * from Table1 ";
rs = st.executeQuery(SQLCMD);
while (rs.next())
{
for(int x = 0; x<=countBHDB; x++){
//name for object array
String now = Integer.toString(x);
nameCC = now+nameC;
Info nameCC = new Info ("t", "d", "c");
List[x] = nameCC;
}
}
rs.close();
} catch (Exception ex) {
System.out.println("Error " + ex);
}
}
}
class Info {
String Name;
String Detail;
String Ability;
Info(String theName, String theDetail, String theAbility) {
Name = theName;
Detail = theDetail;
Ability = theAbility;
}
}