用Java实现数据库的连接,将查询到的数据显示在表中,表能显示但是怎么没有数据,这是我的代码
publicclassCeextendsJFrame{Objectdata[][];Objectcolname[]={"claid","claname"};JTables...
public class Ce extends JFrame {
Object data[][];
Object colname[]={"claid","claname"};
JTable studentTable;
public Ce(){
super("窗口");
data=new Object[3][3];
studentTable=new JTable(data,colname);
this.setLayout(new BorderLayout());
this.add(new JScrollPane(studentTable),BorderLayout.CENTER);
this.setVisible(true);
this.setSize(400, 300);
}
public void actionPerformed(ActionEvent e) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdvcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:liu","liu","123" );
Statement stmt1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from class";
ResultSet rs1=stmt1.executeQuery(sql);
rs1.last();
rs1.afterLast();
int i=0;
while(rs1.previous()){
data[i][0]=rs1.getString(1);
data[i][1]=rs1.getString(2);
i++;
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("bbb");
} catch (SQLException e1) {
// TODO Auto-generated catch block
System.out.println("c");
}
}
public static void main(String args[]) {
new Ce();
}
} 展开
Object data[][];
Object colname[]={"claid","claname"};
JTable studentTable;
public Ce(){
super("窗口");
data=new Object[3][3];
studentTable=new JTable(data,colname);
this.setLayout(new BorderLayout());
this.add(new JScrollPane(studentTable),BorderLayout.CENTER);
this.setVisible(true);
this.setSize(400, 300);
}
public void actionPerformed(ActionEvent e) {
try {
Class.forName("sun.jdbc.odbc.JdbcOdvcDriver");
Connection con1=DriverManager.getConnection("jdbc:odbc:liu","liu","123" );
Statement stmt1=con1.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select * from class";
ResultSet rs1=stmt1.executeQuery(sql);
rs1.last();
rs1.afterLast();
int i=0;
while(rs1.previous()){
data[i][0]=rs1.getString(1);
data[i][1]=rs1.getString(2);
i++;
}
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println("bbb");
} catch (SQLException e1) {
// TODO Auto-generated catch block
System.out.println("c");
}
}
public static void main(String args[]) {
new Ce();
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询