b4是‘查询所有’的按钮跪求如何修改代码实现与数据库连接里面的表名是welfare和wageinfoif(e.getSource()==b4)//查询全部{Connectioncon=null;Statementsql=null;ResultSetrs=null;/...
b4是‘查询所有’的按钮 跪求如何修改代码实现与数据库连接 里面的表名是welfare和wageinfo
if (e.getSource()==b4) // 查询全部
{
Connection con = null;
Statement sql = null;
ResultSet rs=null;
//Vector vector = new Vector();
try {
Class.forName("org.gjt.mm.mysql.Driver");
try {
con = DriverManager.getConnection("jdbc:mysql://localhost:3308/mysq","root","mysql");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
}
catch (ClassNotFoundException e1)
{
JOptionPane.showMessageDialog(this, "连接数据库失败!");
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try
{
//con = DriverManager.getConnection("jdbc:mysql://localhost:3308/mysq","root","mysql");
//sql = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
if(e.getSource()==b4)
{
for(int i=0;i<50;i++)
for (int j=0;j<4;j++)
//table.setValueAt("",i,j);
rs = sql.executeQuery("select distinct * from wageinfo ,welfare where wageinfo.name=welfare.name");
int k = -1;
while (rs.next()) {
++k;
String no = rs.getString(1);
String name = rs.getString(2);
String jb = rs.getString(3);
String jt = rs.getString(6);
int sum=rs.getInt(3)+rs.getInt(6);
table.setValueAt(no, k, 0);
table.setValueAt(name, k, 1);
table.setValueAt(jb, k, 3);
table.setValueAt(jt, k, 2);
//table.setValueAt(sum,k,4);
}
}
} catch (SQLException e1) {
JOptionPane.showMessageDialog(this, "查询失败!");
}
}
展开