-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDbUtils.java
More file actions
42 lines (37 loc) · 948 Bytes
/
Copy pathDbUtils.java
File metadata and controls
42 lines (37 loc) · 948 Bytes
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
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
public class DbUtils
{
public static TableModel resultSetToTableModel(ResultSet rs)
{
try
{
ResultSetMetaData metData = rs.getMetaData();
int numberOfColumns = metData.getColumnCount();
Vector columnNames = new Vector();
for(int column = 0; column<numberOfColumns; column++)
{
columnNames.addElement(metData.getColumnLabel(column + 1));
}
Vector rows = new Vector();
while(rs.next())
{
Vector newRow = new Vector();
for(int i =1; i<=numberOfColumns; i++)
{
newRow.addElement(rs.getObject(i));
}
rows.addElement(newRow);
}
return new DefaultTableModel(rows,columnNames);
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
}