JSP应用开发详解书中,投票程序,更换数据库环境为MySql,导致程序无法运行,先将修改patch提供如下:
数据库环境:MySql
运行效果:
修改代码patch:
diff --git a/WebContent/vote/a/vote.jsp b/WebContent/vote/a/vote.jsp
index cb0e684..8941a37 100644
--- a/WebContent/vote/a/vote.jsp
+++ b/WebContent/vote/a/vote.jsp
@@ -1,11 +1,11 @@
<%@ include file="../vote_include.inc"%>
<%@ page contentType="text/html; charset=utf-8" language="java" %>
-<c:set var="all" value="SELECT 曹操+孙权+刘备+诸葛亮+未确定 as a FROM vote"/>
-<c:set var="vote1" value="SELECT 曹操 as c FROM vote"/>
-<c:set var="vote2" value="SELECT 孙权 as c FROM vote"/>
-<c:set var="vote3" value="SELECT 刘备 as c FROM vote"/>
-<c:set var="vote4" value="SELECT 诸葛亮 as c FROM vote"/>
-<c:set var="vote5" value="SELECT 未确定 as c FROM vote"/>
+<c:set var="all" value="SELECT IFNULL(曹操,0)+IFNULL(孙权,0)+IFNULL(刘备,0)+IFNULL(诸葛亮,0)+IFNULL(未确定,0) as a FROM vote"/>
+<c:set var="vote1" value="SELECT IFNULL(曹操,0) as c FROM vote where id=1"/>
+<c:set var="vote2" value="SELECT IFNULL(孙权,0) as c FROM vote where id=1"/>
+<c:set var="vote3" value="SELECT IFNULL(刘备,0) as c FROM vote where id=1"/>
+<c:set var="vote4" value="SELECT IFNULL(诸葛亮,0) as c FROM vote "/>
+<c:set var="vote5" value="SELECT ifnull(未确定,0) as c FROM vote where id=1"/>
<sql:query sql="${all}" var="queryall" dataSource="${vote}"/>
<c:forEach var="row" items="${queryall.rows}">
@@ -24,7 +24,7 @@
<td width="83%" align="center">得票率</td>
</tr>
<tr>
- <sql:query var="query" dataSource="${vote}">
+ <sql:query sql = "${vote1}" var="query" dataSource="${vote}">
SELECT 曹操 as c FROM vote
</sql:query>
<td><a href="vote_do.jsp?id=曹操">曹操 </a></td>
@@ -35,7 +35,7 @@
</td>
</tr>
<tr>
- <sql:query var="query" dataSource="${vote}">
+ <sql:query sql = "${vote4}" var="query" dataSource="${vote}">
SELECT 诸葛亮 as c FROM vote
</sql:query>
<td><a href="vote_do.jsp?id=诸葛亮">诸葛亮</a></td>
@@ -46,7 +46,7 @@
</td>
</tr>
<tr>
- <sql:query var="query" dataSource="${vote}">
+ <sql:query sql = "${vote3}" var="query" dataSource="${vote}">
SELECT 刘备 as c FROM vote
</sql:query>
<td><a href="vote_do.jsp?id=刘备">刘备</a></td>
@@ -57,7 +57,7 @@
</td>
</tr>
<tr>
- <sql:query var="query" dataSource="${vote}">
+ <sql:query sql = "${vote2}" var="query" dataSource="${vote}">
SELECT 孙权 as c FROM vote
</sql:query>
<td><a href="vote_do.jsp?id=孙权">孙权</a></td>
@@ -68,7 +68,7 @@
</td>
</tr>
<tr>
- <sql:query var="query" dataSource="${vote}">
+ <sql:query sql = "${vote5}" var="query" dataSource="${vote}">
SELECT 未确定 as c FROM vote
</sql:query>
<td><a href="vote_do.jsp?id=未确定">未确定</a></td>
代码下载:http://download.csdn.net/download/hailushijie/9874752
关注我的技术公众号,查看更多优质技术文章推送
微信扫一扫下方二维码即可关注: