protected final Vector executeQuery(String sql) {
Vector v = new Vector();
try {
Connection conn = DriverManager.getConnection(URL, USER, PASSWORD);
stmt = conn.createStatement();
rst = stmt.executeQuery(sql);
/*可用于获取关于 ResultSet 对象中列的类型和属性信息的对象。
* An object that can be used to obtain information about the type and properties of columns in a ResultSet object.
* */
ResultSetMetaData rsmd = rst.getMetaData();
//返回此 ResultSet 对象中的列数。Returns the number of columns in this ResultSet object.
int count = rsmd.getColumnCount();
Vector row = null;
while(rst.next()){
row = new Vector();
//给一条记录赋值 Assign a value to a record
for (int i = 0; i < count; i++) {
row.add(rst.getObject(i+1));
}
//把一条记录加入v中 Add a record to "v"
v.add(row);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
this.closeAll();
}
return v;
}
title = new Vector();
title.add("项目编号");
title.add("收费名称");
title.add("收费金额");
title.add("收费单位");
title.add("收费周期");
title.add("备注");
data = bxidi.showAll();
table = new JTable(data, title);
sp.setViewportView(table);
tm = new DefaultTableModel(data,title);
table.setModel(tm);