star123456789
发贴: 4
|
于 2006-10-20 17:45
<%@ 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
|