大家帮我看看为什么连接数据库后返回的数据为空?*帮帮忙呀
这个是Controller===============================================
package site;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class MainController extends HttpServlet
{
public void inti() throws ServletException
{
}
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
doPost(req,res);
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException
{
try
{
ItemCollection collection =new ItemDao().findAll();
ServletContext app=getServletContext();
app.setAttribute("collection",collection);
}
catch(Exception ex)
{
ex.printStackTrace();
}
ServletContext context=getServletContext();
RequestDispatcher rd=context.getRequestDispatcher("/jsp/top.jsp");
rd.forward(req,res);
}
}
========================================================
这个是DAo
package site;
import java.sql.*;
import java.util.*;
public class ItemDao
{
public ItemDao(){}
private Connection createConn()
{
// String url="jdbc:mysql://localhost:3306/chumomosite? useUnicode=true&characterEncoding=Shift-JIS";
// String dri="com.mysql.jdbc.Driver";
String dri="oracle.jdbc.driver.OracleDriver";
String url="jdbc:oracle:thin:@riyuu:1521:chumomo";
try
{
Class.forName(dri);
Connection con=DriverManager.getConnection(url,"root","1234");
Connection con=DriverManager.getConnection(url,"system","uuuu1234");
return con;
}
catch(SQLException ex)
{
ex.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
return null;
}
private void closeConn(Connection con)
{
try
{
con.close();
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
public ItemCollection findAll()
{
ItemCollection collection=new ItemCollection();
collection.setList(new ArrayList());
String sql="select * from item";
Connection con=createConn();
try
{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery(sql);
while(rs.next())
{
int id=rs.getInt("id");
String name=rs.getString("name");
int price=rs.getInt("price");
String detail=rs.getString("detail");
String picture=rs.getString("picture");
collection.addItem(new Item(id,name,price,detail,picture));
}
rs.close();
stmt.close();
return collection;
}
catch(SQLException ex)
{
ex.printStackTrace();
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
closeConn(con);
}
return null;
}
}
这个是获取的数据集-————————————————————————
package site;
import java.util.ArrayList;
public class ItemCollection
{
protected ArrayList mList;
public ItemCollection(){}
public ArrayList getList()
{
return this.mList;
}
public void addItem(Item item)
{
mList.add(item);
}
public void setList(ArrayList list)
{
this.mList=list;
}
public Item getItem(int index)
{
return (Item)mList.get(index);
}
public int getSize()
{
return this.mList.size();
}
}
这个是记录——————————————
package site;
public class Item {
private int mId;
private String mName;
private String mDetail;
private String mPictureName;
private int mPrice;
public Item(){}
public Item(int id,String name,int price,
String detail,String picture)
{
this.mId=id;
this.mName=name;
this.mDetail=detail;
this.mPictureName =picture;
this.mPrice =price;
}
public int getId()
{
return mId;
}
public String getName()
{
return mName;
}
public String getDetail()
{
return mDetail;
}
public String getPicture()
{
return mPictureName;
}
}