Can some one please help with this error?
Thanks in advance.
JFrame_1.java [108:1] local variable strings is accessed from within inner class; needs to be declared final
public int getSize() { return strings.length; }
***********
with this code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String[] strings = new String[5];
int myNumber = 0;
String dbURL = "jdbcdbc:myDB";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch (ClassNotFoundException e) {
System.out.println("Database access failed " + e);
}
try {
Connection conn = DriverManager.getConnection(dbURL,"*****","*****");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select firstName from GetConReg where lastName != ''");
while(rs.next()){
strings[myNumber] = rs.getString(1);
myNumber++;
}
}catch (SQLException e) {
System.out.println("Database access failed " + e);
}
jList1.setModel(new javax.swing.AbstractListModel() {
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings; }
});
}
***********
Thanks in advance.
JFrame_1.java [108:1] local variable strings is accessed from within inner class; needs to be declared final
public int getSize() { return strings.length; }
***********
with this code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
String[] strings = new String[5];
int myNumber = 0;
String dbURL = "jdbcdbc:myDB";
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch (ClassNotFoundException e) {
System.out.println("Database access failed " + e);
}
try {
Connection conn = DriverManager.getConnection(dbURL,"*****","*****");
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select firstName from GetConReg where lastName != ''");
while(rs.next()){
strings[myNumber] = rs.getString(1);
myNumber++;
}
}catch (SQLException e) {
System.out.println("Database access failed " + e);
}
jList1.setModel(new javax.swing.AbstractListModel() {
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings; }
});
}
***********