Witam! Mam aplikację, która łączy się z bazą i pobiera z bazy danych tabele i wypełnia tymi danymi tabelę JTable w moim oknie (JFrame)...Oto kod:
public class Pobranie_tabel
{
private JComboBox combo_sortowanie;
private String selectedItem;
public Pobranie_tabel(JComboBox combo)
{
combo_sortowanie=combo;
//System.out.println("ddddd "+combo_sortowanie.getName().toString());
combo_sortowanie.removeAllItems();
}
static String relacja;
public DefaultTableModel Pobierz_model(String zapytanie, String tableName) throws SQLException
{
String query=zapytanie;
relacja=new String(tableName);
CachedRowSetImpl crs=new CachedRowSetImpl();
DefaultTableModel tModel=null;
try
{
rs = Polaczenie.conn.createStatement().executeQuery(query);
ResultSetMetaData rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
String[] colHeaders = new String[colCount];
tModel = new DefaultTableModel()
{
@Override
public boolean isCellEditable(int rowIndex, int columnIndex)
{
if(relacja.equals("Stanowisko"))
{
if(columnIndex==0) return false;
}
else if(relacja.equals("Dzial"))
{
if(columnIndex==0) return false;
}
else if(relacja.equals("Pracownik"))
{
if(columnIndex==0) return false;
if(columnIndex==1) return false;
if(columnIndex==2) return false;
if(columnIndex==3) return false;
if(columnIndex==4) return false;
if(columnIndex==5) return false;
if(columnIndex==6) return false;
if(columnIndex==7) return false;
if(columnIndex==8) return false;
if(columnIndex==9) return false;
}
else if(relacja.equals("L_godzin"))
{
if(columnIndex==0) return false;
if(columnIndex==1) return false;
}
return true;
}
};
for(int i=0;i<colCount;i++)
{
colHeaders[i] = rsmd.getColumnName(i+1);
combo_sortowanie.addItem(colHeaders[i]);
}
tModel.setColumnIdentifiers(colHeaders);
while(rs.next())
{
Object[] obj = new Object[colCount];
for(int i=0;i<colCount;i++)
{
obj[i] = rs.getObject(i+1);
}
tModel.addRow(obj);
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(null,"Nie mozna pobrac danych z bazy: "+ex.getMessage(),"ERROR", JOptionPane.ERROR_MESSAGE);
}
return tModel;
}
}
Problem jest taki, że teraz ten mój cały program muszę przerobić na RMI (Remote Method Invocation), czyli muszę ResultSet zamienić na CachedRowSetImpl...Pytanie jak to tutaj zastosować, np do resultSetMetaData...Ktoś zna się na tym? Szukam eksperta w tej dziedzinie...