
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") //加载驱动器类
Connection con = DriverManager.getConnection("jdbc:odbc:JuneText", "", "") //创建的JuneText数据源名称
Statement statement = con.createStatement()//创建执行对象
String sql=null
String id = jtf2.getText().trim()
if (id.equals("")) {
sql = "select * from student"
} else {
sql = "select * from student where 学号='" + id + "'"
}
ResultSet rs = statement.executeQuery(sql)
int i = 0, j = 0
while (rs.next()) {
jTable1.setValueAt(rs.getString(1), i, j)
jTable1.setValueAt(rs.getString(2), i, j + 1)
jTable1.setValueAt(rs.getString(3), i, j + 2)
jTable1.setValueAt(rs.getString(4), i, j + 3)
jTable1.setValueAt(rs.getString(5), i, j + 4)
i = i + 1
j = 0
}
rs.close()
statement.close()
} catch (Exception e) {
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)