java读取数据库写入jTable
小弟初学,在用java读取数据库写入jTable中的时候只能显示一行,请求帮助.Stringme=mex.getText();if("0".equals(me)){try...
小弟初学,在用java读取数据库写入jTable中的时候只能显示一行,请求帮助.
String me=mex.getText();
if("0".equals(me))
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:kmgl","","");
String sql="select * from km";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
int i = 0;
String xkh=rs.getString(1).trim();
String xmm=rs.getString(2).trim();
String xme=rs.getString(3).trim();
String xsy=rs.getString(4).trim();
biao.setValueAt(xkh, i, 0);
biao.setValueAt(xmm, i, 1);
biao.setValueAt(xme, i, 2);
biao.setValueAt(xsy, i, 3);
i++;
}
rs.close();
con.close();
}
catch(Exception e){
System.out.print(e.getMessage());
}
}
else {}
} 展开
String me=mex.getText();
if("0".equals(me))
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:kmgl","","");
String sql="select * from km";
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
int i = 0;
String xkh=rs.getString(1).trim();
String xmm=rs.getString(2).trim();
String xme=rs.getString(3).trim();
String xsy=rs.getString(4).trim();
biao.setValueAt(xkh, i, 0);
biao.setValueAt(xmm, i, 1);
biao.setValueAt(xme, i, 2);
biao.setValueAt(xsy, i, 3);
i++;
}
rs.close();
con.close();
}
catch(Exception e){
System.out.print(e.getMessage());
}
}
else {}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询