在工程中,WebRoot中index.jsp可以查询得到SQL server的数据,而view中index.jsp却不能,求解,查询代码如下
public class GoodsDao {
@SuppressWarnings("finally")
public ArrayList queryAllGoods(){
Connection conn=null;
ArrayList goodss =new ArrayList();
try{
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL=
"jdbc:sqlserver://localhost:1433;DatabaseName=phoneShop";
String username="student";
String userpsd="888657";
Class.forName(driverName);
conn=DriverManager.getConnection(dbURL,username,userpsd);
String sql="select * from Goods";
Statement stat=conn.createStatement();
ResultSet rs=stat.executeQuery(sql);
while(rs.next()){
Goods goods=new Goods();
goods.setGoods_id(rs.getInt("Goods_id"));
goods.setGoods_name(rs.getString("Goods_name"));
goods.setGoods_make(rs.getString("Goods_make"));
goods.setGoods_type(rs.getString("Goods_type"));
goods.setGoods_price(rs.getInt("Goods_price"));
goods.setGoods_description(rs.getString("Goods_description"));
goods.setStore_id(rs.getInt("Store_id"));
goodss.add(goods);
System.out.print(goods.getGoods_id());
System.out.print(goods.getGoods_name());
}
rs.close();
stat.close();
}
catch(Exception el){
el.printStackTrace();
}
finally
{
try{
if(conn!=null){
conn.close();
conn=null;
}
}
catch(Exception ex){
}
return goodss;
}
}