日期:2014-05-18  浏览次数:20755 次

关于JSP中数据库的问题?
SQL2000数据库,我是想把表shouTable中的count项的值付给数据表monthTble相对应的receive项,程序运行没有报错,但是count的值并没有付给receive,请高手帮忙看下,小弟感激不尽!


<%@   page   contentType= "text/html;   charset=gb2312 "   language= "java "   import= "java.sql.* "   errorPage= " "   %>
<%@   include   file= "checkadmin.jsp "%>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.01   Transitional//EN "   "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>  
<body>
<%
String   s=session.getAttribute( "s ").toString();
String   sqlString= "select   *   from   shouTable     where     s_date   like   '% "+s+ "% ' ";
try  
        {   Connection   con;
            Statement   sql1,sql2,sql3;
    ResultSet   rs,rs1;
            Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
            con=DriverManager.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=shangdianDB ", "sa ", " ");
            sql1=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    sql2=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
    sql3=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
            rs=sql1.executeQuery(sqlString);
    while(rs.next()){
    String   e_name=rs.getString( "e_name ");
    String   e_size=rs.getString( "e_size ");
    int   count=Integer.parseInt(rs.getString( "amount "));
    rs1=sql2.executeQuery( "select   *   from   monthTable   where   e_name= ' "+e_name+ " '   and   e_size= ' "+e_size+ " '     and   mon= ' "+s+ " ' ");
    rs1.next();  
    int   receive=rs1.getInt( "receive ");
    int   amount=count+receive;
    sql3.executeUpdate( "update   monthTable   set   receive= "+amount+ "   where   e_name= ' "+e_name+ " '   and   e_size= ' "+e_size+ " '   and   mon= ' "+s+ " ' ");
   
    }
    con.close();
      }
  catch(SQLException   e1)  
        {
            out.print(e1);
        }
  %>  
    <%response.sendRedirect( "mon3.jsp ");%>
</body>
</html>


------解决方案--------------------
把你的sql语句先打印出来,在查询分析器执行看看有没有错.