jdbc利用集合传递参数

来源:互联网 发布:seo新手教程 编辑:程序博客网 时间:2024/05/18 06:28
public static List<Emp> queryColor() {
// TODO Auto-generated method stub
List<Emp> table =new ArrayList<Emp>();
Connection con=null;
Statement sta=null;
ResultSet re=null;
String sql="select * from emp";
try {
con=JdbcUtil.getConn();
sta=con.createStatement();
re=sta.executeQuery(sql);
while(re.next())
{
Emp emp=new Emp();
emp.setName(re.getString("name"));
emp.setId(re.getInt("id"));

table.add(emp);
System.out.println(emp);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally
{

}




return table;
}