java的swing开发查询只显示表头没有数据是什么意思
主要代码代码如下://查询if(e.getSource()==select){try{//this.fireTableStructureChanged();//this....
主要代码代码如下:
// 查询
if (e.getSource() == select) {
try{
//this.fireTableStructureChanged();
//this.fireTableDataChanged();
//v.removeAllElements();
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433; DatabaseName=尚清丽",
"sql", "sql0708");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String tempSql = "select * from eminformation where employ_number='"+num+"'";
ResultSet rs=st.executeQuery(tempSql);
ResultSetMetaData rsmd=rs.getMetaData();
cols=rsmd.getColumnCount();
//headers=new String[cols];
for(int i=1;i<cols ;i++){
colum.addElement(rsmd.getColumnName(i));
}
if(!rs.next()){
JOptionPane.showMessageDialog(null,"没有相关记录!!");
}
else{
//this.fireTableStructureChanged();
//this.fireTableDataChanged();
rs.beforeFirst();
while (rs.next()){
Vector currow = new Vector();
for(int i=1;i<cols;i++){
currow.addElement(rs.getString(i));
}
rows.addElement(currow);
}
tabel = new JTable(rows, colum);
b4.add(tabel, BorderLayout.CENTER);
tabel.setVisible(true);
tabel.setRowHeight(50);
b4.add(new JScrollPane(tabel), BorderLayout.CENTER);
} 展开
// 查询
if (e.getSource() == select) {
try{
//this.fireTableStructureChanged();
//this.fireTableDataChanged();
//v.removeAllElements();
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(
"jdbc:sqlserver://localhost:1433; DatabaseName=尚清丽",
"sql", "sql0708");
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
String tempSql = "select * from eminformation where employ_number='"+num+"'";
ResultSet rs=st.executeQuery(tempSql);
ResultSetMetaData rsmd=rs.getMetaData();
cols=rsmd.getColumnCount();
//headers=new String[cols];
for(int i=1;i<cols ;i++){
colum.addElement(rsmd.getColumnName(i));
}
if(!rs.next()){
JOptionPane.showMessageDialog(null,"没有相关记录!!");
}
else{
//this.fireTableStructureChanged();
//this.fireTableDataChanged();
rs.beforeFirst();
while (rs.next()){
Vector currow = new Vector();
for(int i=1;i<cols;i++){
currow.addElement(rs.getString(i));
}
rows.addElement(currow);
}
tabel = new JTable(rows, colum);
b4.add(tabel, BorderLayout.CENTER);
tabel.setVisible(true);
tabel.setRowHeight(50);
b4.add(new JScrollPane(tabel), BorderLayout.CENTER);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询