JSP如果调取数据库中表的数据 用的是ArrayList方法
2个回答
展开全部
给你一个参照:
public Iterator ListAddress(int m_id){
ConnectionDB gs=new ConnectionDB();
Connection con;
ArrayList<Address> arraylist = new ArrayList<Address>();
String str = "select * from address where m_id="+m_id;
try
{
con=gs.getConnection();
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(str);
while(rs.next())
{
Address address=new Address();
address.setA_id(rs.getInt(1));
address.setM_id(rs.getInt(2));
address.setName(rs.getString(3));
address.setAddress(rs.getString(4));
address.setPostalcose(rs.getInt(5));
address.setPnumber(rs.getString(6));
arraylist.add(address);
}
rs.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
return arraylist.iterator();
}
public Iterator ListAddress(int m_id){
ConnectionDB gs=new ConnectionDB();
Connection con;
ArrayList<Address> arraylist = new ArrayList<Address>();
String str = "select * from address where m_id="+m_id;
try
{
con=gs.getConnection();
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(str);
while(rs.next())
{
Address address=new Address();
address.setA_id(rs.getInt(1));
address.setM_id(rs.getInt(2));
address.setName(rs.getString(3));
address.setAddress(rs.getString(4));
address.setPostalcose(rs.getInt(5));
address.setPnumber(rs.getString(6));
arraylist.add(address);
}
rs.close();
}
catch(Exception ee)
{
ee.printStackTrace();
}
return arraylist.iterator();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询