大家帮我看看为什么连接数据库后返回的数据为空?*帮帮忙呀

Chumomo 2005-03-07 05:00:44
这个是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;
}
}
...全文
98 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

67,541

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧