Hoe krijg ik een java.sql.ResultSet zo snel mogelijk in een JTable ?? Ik had geen zin om per cel value's te gaan toewijzen emt for-loopjes, leek me een beetje traag.
Wie helpt mij uit de brand ??
Wie helpt mij uit de brand ??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
| import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
public class QueryResultModel extends AbstractTableModel
{
private List colNames;
private String[][] data;
private int [] maxChars;
private int nrCols;
private int nrRows;
public QueryResultModel(ResultSet rs) throws SQLException
{
colNames = DatabaseTools.getColumnNames(rs);
nrCols = colNames.size();
nrRows = 0;
ArrayList dataList = new ArrayList();
while(rs.next())
{
for(int i = 1; i < (nrCols + 1); i++)
{
dataList.add(rs.getString(i));
}
nrRows++;
}
data = new String[nrRows][nrCols];
int index=0;
for(int i=0;i<nrRows;i++)
{
for(int j=0;j<nrCols;j++)
{
data[i][j] = (String)dataList.get(index);
index++;
}
}
}
public int getRowCount()
{
return nrRows;
}
public int getColumnCount()
{
return nrCols;
}
public String getColumnName(int columnIndex)
{
return (String) colNames.get(columnIndex);
}
public Object getValueAt(int rowIndex,int columnIndex)
{
return data[rowIndex][columnIndex];
}
} |
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
| package com.md.jdb;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import java.io.Serializable;
public class QueryResultModel extends AbstractTableModel implements Serializable {
private List colNames;
private String[][] data;
private int [] maxChars;
private int nrCols;
private int nrRows;
public QueryResultModel(ResultSet rs) throws SQLException {
ResultSetMetaData DatabaseTools = rs.getMetaData();
for(int a=1;a<=DatabaseTools.getColumnCount();a++) {
colNames.add(DatabaseTools.getColumnName(a));
}
nrCols = colNames.size();
nrRows = 0;
ArrayList dataList = new ArrayList();
while(rs.next())
{
for(int i = 1; i <=(nrCols); i++)
{
dataList.add(rs.getString(i));
}
nrRows++;
}
data = new String[nrRows][nrCols];
int index=1;
for(int i=1;i<nrRows;i++)
{
for(int j=1;j<nrCols;j++)
{
data[i][j] = (String)dataList.get(index);
index++;
}
}
}
public int getRowCount()
{
return nrRows;
}
public int getColumnCount()
{
return nrCols;
}
public String getColumnName(int columnIndex)
{
return (String) colNames.get(columnIndex);
}
public Object getValueAt(int rowIndex,int columnIndex)
{
return data[rowIndex][columnIndex];
}
} |
Backup not found (R)etry (A)bort (P)anic<br\>AMD 3400+ 64, 2 GB DDR, 1,5 TB Raid5
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment
1
2
3
4
5
6
7
8
9
10
11
12
13
| public static List getColumnNames(ResultSet rs) throws SQLException
{
ResultSetMetaData meta = rs.getMetaData();
int nrCols = meta.getColumnCount();
List result = new ArrayList(nrCols);
for(int i = 1; i <= nrCols; i++)
{
result.add(meta.getColumnName(i));
}
return result;
} |
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment
Nee: sterke koffieMisterData: vitaminepillen ???
Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment