当前位置: 代码迷 >> Java Web开发 >> 初学者上路 请各位帮小弟我看一下这个数据库调用好吗
  详细解决方案

初学者上路 请各位帮小弟我看一下这个数据库调用好吗

热度:201   发布时间:2016-04-12 22:46:07.0
菜鸟上路 请各位帮我看一下这个数据库调用好吗
我的目标是  调用数据库中的一个商品表  但是根本调不出来   得到的是商品是一个null

我的Servlet是:


protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletExceptionIOException {
         response.setContentType("text/html;charset=UTF-8");
         PrintWriter out = response.getWriter();
         StringBuffer str = new StringBuffer();
         ShowGoods sh = new ShowGoods();
         HttpSession session = request.getSession(true);
        session.setAttribute("s", sh);
        
        try
            {
                Statement sta = dbcon.getcon().createStatement();
                ResultSet rs = sta.executeQuery("select * from goods");
                str = tablegoods.getTable(rs);
                sh.setQueryResult(str);
            }
            catch(Exception e)
            {
                str.append(e);
            }
            RequestDispatcher dis = request.getRequestDispatcher("GoodsList.jsp");
            dis.forward(request, response);
        }


调用表的java是

             public class tablegoods {
            public static StringBuffer getTable(ResultSet rs) throws Exception
    {
            StringBuffer str = new StringBuffer();
  相关解决方案