display sqlite datatable in a jtable
Posted
by tuxou
on Stack Overflow
See other posts from Stack Overflow
or by tuxou
Published on 2010-05-17T12:06:54Z
Indexed on
2010/05/17
12:10 UTC
Read the original article
Hit count: 426
Hi
I'm trying to display an sqlite data table in a jtable but i have an error " sqlite is type forward only"
how could I display it in a jtable
try {
long start = System.currentTimeMillis();
Statement state = ConnectionBd.getInstance().createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY
);
ResultSet res = state.executeQuery("SELECT * FROM data");
ResultSetMetaData meta = res.getMetaData();
Object[] column = new Object[meta.getColumnCount()];
for(int i = 1 ; i <= meta.getColumnCount(); i++){
column[i-1] = meta.getColumnName(i);
}
res.last();
int rowCount = res.getRow();
Object[][] data = new Object[res.getRow()][meta.getColumnCount()];
res.beforeFirst();
int j = 1;
while(res.next()){
for(int i = 1 ; i <= meta.getColumnCount(); i++)
data[j-1][i-1] = res.getObject(i);
j++;
}
res.close();
state.close();
long totalTime = System.currentTimeMillis() - start;
result.removeAll();
result.add(new JScrollPane(new JTable(data, column)), BorderLayout.CENTER);
result.add(new JLabel("execute in " + totalTime + " ms and has " + rowCount + " ligne(s)"), BorderLayout.SOUTH);
result.revalidate();
} catch (SQLException e) {
result.removeAll();
result.add(new JScrollPane(new JTable()), BorderLayout.CENTER);
result.revalidate();
JOptionPane.showMessageDialog(null, e.getMessage(), "ERREUR ! ", JOptionPane.ERROR_MESSAGE);
}
thank you
© Stack Overflow or respective owner