Array dimension protocol

M

Mariano

I've this class, initially I declared an array of string as private
(like malattieList), the method cbxDataIngrssoItemStateChanged and
formWindowOpened associate an array returned from creaLista method to
private array malattieList. This array is composed by the rows in a
column of a ResulSet.

==========================================
package cc;
import java.sql.*;
import java.util.ArrayList;

public class Paziente extends javax.swing.JFrame {
private String[] sintomiList, malattieList;
private MyDBConn mdbc;
//...
private void cbxDataIngressoItemStateChanged(java.awt.event.ItemEvent
evt) {
ResultSet gen, mal;
mal=mdbc.inviaQuery("SELECT * FROM .....");
gen=mdbc.inviaQuery("SELECT * FROM .....");

try {
gen.first();
malattieList = creaLista(mal, "MALATTIA");
// il metodo seguente è la specifica di creaLista()
//...
} catch (SQLException ex) {
alerts.showErr(ex.getMessage());
}

mdbc.close(gen);
mdbc.close(mal);

}

private String[] creaLista(ResultSet cursore, String tipo) throws
SQLException {
cursore.beforeFirst();
ArrayList<String> lista=new ArrayList<String>();
while(cursore.next())
lista.add(cursore.getString(tipo));
return lista.toArray(new String[lista.size()]);

}

private void formWindowOpened(java.awt.event.WindowEvent evt)
{

ResultSet gen, mal;
gen=mdbc.inviaQuery("SELECT * FROM ...");
mal=mdbc.inviaQuery("SELECT * FROM ...");
try {
gen.first();
// ...
malattieList = creaLista(mal, "MALATTIA");
} catch (SQLException ex) {
alerts.showErr(ex.getMessage());
}

mdbc.close(gen);
mdbc.close(mal);
}

==========================================

After all the malattieList private array is being used by constructor
of jList, and show malattieList element. Below the constructor of
jList:

==========================================
new javax.swing.AbstractListModel() {
public int getSize() { return malattieList.length; }
public Object getElementAt(int i) { return
malattieList; }
}
==========================================

All seems work properly but there's a problem: when class start,
formWindowOpened is executed, query start, resultset is created, a
column of resultSet is used by creaLista method, an array returned and
this array passed to constructor of jList to show result in the jList.

Now, if formWindowOpened have showed (5 elements) in jList, when I
call cbxDataIngressoItemStateChanged if new ResultSet has more of 5
elements its are not showed. No problem if new ResulSet has <= 5
elements.

Who can help me to find an universal solution????
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,609
Members
45,253
Latest member
BlytheFant

Latest Threads

Top