package myproj;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import myproj.util.DBUtil;
/**
*
* @author PEARL
*/
public class DATAENTRY extends javax.swing.JFrame {
/**
* Creates new form DATAENTRY
*/
public DATAENTRY() {
try {
initComponents();
DBUtil util = new DBUtil();
Connection con = util.getConnection();
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select * from bk_det inner join bk_rep on bk_det.rm_id = bk_rep.rm_id inner join bk_sec on bk_rep.rm_id = bk_sec.rm_id inner join mut_det on bk_sec.rm_id = mut_det.rm_id inner join rm_det on mut_det.rm_id = rm_det.rm_id inner join soil_det on rm_det.rm_id = soil_det.rm_id");
ResultSetMetaData rsmetadata = rs.getMetaData();
int columns = rsmetadata.getColumnCount();
DefaultTableModel dtm = new DefaultTableModel();
Vector columns_name = new Vector();
Vector data_rows = new Vector();
for(int i=1; i< columns; i++){
columns_name.addElement(rsmetadata.getColumnName(i));
}
dtm.setColumnIdentifiers(columns_name);
while(rs.next()){
data_rows = new Vector();
for(int j=1; j< columns; j++){
data_rows.addElement(rs.getString(j));
}
dtm.addRow(data_rows);
}
MyTable.setModel(dtm);
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
Logger.getLogger(Demo.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String arg[]){
}
}
我想在netbeans gui中将我的sql数据库中的记录显示到我的jtable,但能够成功显示编译和运行windows窗体,但它不显示受尊重的窗体请帮忙