grade是个类,如
class grade{
String name;
String chengji;
public String getEname(){
return name;
}
public void setEname(String name){
this.name=name;
}
public String getchengji(){
return chengji;
}
public void setchengji(String chengji){
this.chengji=chengji;
}
}
name和chengji是要从数据库读到JTable里。
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String connectionURL="jdbc:odbc:Liall";
String sql="select * from myall";
con=DriverManager.getConnection(connectionURL);
PreparedStatement ps=con.prepareStatement(sql);
ResultSet rs=ps.executeQuery();
while(rs.next()){
wo=new Wo();
wo.setEname(rs.getString(1));
wo.setEchengji(rs.getString(2));
all.add(wo);
}
}catch(Exception e){
System.out.println("SQLException:"+e.getMessage());
}
finally{
try{
con.close();
}catch(Exception e){
System.out.println("SQLException:"+e.getMessage());
}
}
JTable(Vector rowData, Vector columnNames)
求例子