用JTable显示ACCESS2000数据

//省略了窗口代码

 Vector vName=new Vector();
 Vector vData=new Vector();
 Vector r;
        try {
            String strurl="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=E://MyDB.mdb";
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection conn=DriverManager.getConnection(strurl);
            Statement stmt=conn.createStatement();
            ResultSet rs=stmt.executeQuery("select * from STUDENT");
            for(int i=0;i<rs.getMetaData().getColumnCount();i++)
            {
                vName.add(rs.getMetaData().getColumnName(i+1));
            }
            while(rs.next()) {
                r=new Vector();
                for(int k=0;k<rs.getMetaData().getColumnCount();k++)
                r.add(rs.getString(k+1));
                vData.add(r);
            }
            conn.close();
           
        }catch(Exception e) {
            System.out.println(e);
        }
       
        DefaultTableModel dtm=new DefaultTableModel();
        dtm.setDataVector(vData,vName);
        this.jTable1.setModel(dtm); 

你可能感兴趣的:(exception,exception,jdbc,jdbc,jdbc,vector,vector,Microsoft,Microsoft,Access,Access,Access)