Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Servlet/JSP/JSF/JavaFX Script » 精华  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
reply to postflat modethreaded modego to previous topicgo to next topicgo to back
作者 数据库更新问题
star123456789





发贴: 4
于 2006-10-20 17:45 user profilesend a private message to userreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.sql.*" %>

<jsp:useBean id="dbConnectBean" scope="page" class="dbConnect.dbConnect"/>

<html>
   <body bgcolor="beige">
     <h2><center>成绩单</center><hr></h2>
     <%
       int score = 0;
       String tihao = "";
       String Sel = "";
       String Ans = "";
       String Lesson = request.getParameter("Lesson");
      String Id = request.getParameter("Id");
      String Name = request.getParameter("Name");
      String sql = "select * from "+Lesson+ " order by number";  
      ResultSet rs = dbConnectBean.executeQuery("exam", sql);
       while(rs.next())
       {
         tihao = rs.getString("number");
         if (request.getParameter("No"+tihao)!=null)
         {
           Sel = request.getParameter("No"+tihao);
           Ans = rs.getString("answer");
//           out.print("<br>No"+tihao+". Your answer:"+Sel +", The correct answer:"+Ans);
           if (Ans.equals(Sel))
           {
             score = score+rs.getInt("score");
//             out.print("<font color=red> OK!</font>");
           }
         }
       }
       try{
         if(rs != null)
           rs.close();
         dbConnectBean.close();
       }
       catch(SQLException e){
         System.out.println (e.getMessage());
       }
      %>
     
      <%
        sql = "select * from scores where id='" +Id +"'"+" and name='"+Name+"'";
        int iscore = 0;
        rs = dbConnectBean.executeQuery("exam", sql);
        rs.next();
      iscore = rs.getInt(Lesson);
        if (iscore == -1)
        {
          out.print("<br>你还没有考过这门课" + ",当前成绩为:"+score);
          sql = "update scores set " +Lesson+ "=" +score+ " where id='" +"Id" +"'"+
              " and name='"+Name+"'";
          dbConnectBean.executeUpdate("exam", sql);          out.print("<br>更新成功");
        }
        else
          out.print("<script>{alert('你已经考过了')}</script>");
        try{
         if(rs != null)
           rs.close();
         dbConnectBean.close();
       }
       catch(SQLException e){
         System.out.println (e.getMessage());
       }
      %>
     
      <center>
      <br><%= Name %>同学你好,你的考试成绩统计为:<br>
        <table border=2 bgcolor='#f1f1f1' width=80%>
        <tr bgcolor='#dddddd'><td>你参加的科目</td><td>你的分数</td></tr>
        <%
          sql = "select * from scores where id='" +Id +"'"+" and name='"+Name+"'";
          int iJsp = 0;
          int iXml = 0;
          rs = dbConnectBean.executeQuery("exam", sql);
          rs.next();
          iJsp = rs.getInt("JSP");
          iXml = rs.getInt("XML");
         %>
         <tr><td>JSP</td><td align="right"><%= iJsp %></td></tr>
         <tr><td>XML</td><td align="right"><%= iXml %></td></tr>
         </table>
         <%
           try{
              if(rs != null)
                rs.close();
              dbConnectBean.close();
            }
            catch(SQLException e){
              System.out.println (e.getMessage());
            }
         %>
      </center>
      <hr><a href="login.jsp">参加其他科目考试</a>
   </body>
</html>
为什么数据库更新不成功?求答案。
我的设想是在数据库中查找还没有考过的课程,(即初始数值为-1的值),更新数据库,然后再查询数据库显示更新后的数值。可执行结果是显示更新完成了,但数据库中值却没有变,数据库为.mdb,文件属性并不是只读。(配置为tomcat5.0)


star123456789 edited on 2006-10-20 17:50


话题树型展开
人气 标题 作者 字数 发贴时间
1579 数据库更新问题 star123456789 6862 2006-10-20 17:45
1317 JavaBean文件内容 star123456789 1506 2006-10-20 17:51

reply to postflat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923