注册 登录
编程论坛 J2EE论坛

投票的问题

smoon 发布于 2006-12-23 20:53, 940 次点击

代码都贴出来拉。。就是为什么不循环呀?
每次都是就显示一个投票结果。。。。
是那的问题???第一回做。。。


<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page language="java" import="java.sql.*"%>
<%--
The taglib directive below imports the JSTL library. If you uncomment it,
you must also add the JSTL library to the project. The Add Library... action
on Libraries node in Projects view can be used to add the JSTL 1.1 library.
--%>
<%--
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
--%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>投票结果</title>
<% out.println("jsptoupiao");
try
{
Connection con=null;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:music","sa","");

PreparedStatement s= con.prepareStatement("select * from music where nume>0 order by nume desc");
ResultSet r=s.executeQuery();%>
<table border=2>
<%

while(r.next()){
%>


<tr>
<td><%=r.getString("musicname")%></td>
<td><img src=images/dot.gif height=13 width=<%=r.getString("nume")%>></td>
<td><%=r.getString("nume")%></td>
</tr>


<% }%>
</table><%
}

catch(Exception e)
{}

%>
</head>
<body>



<%--
This example uses JSTL, uncomment the taglib directive above.
To test, display the page like this: index.jsp?sayHello=true&name=Murphy
--%>
<%--
<c:if test="${param.sayHello}">
<!-- Let's welcome the user ${param.name} -->
Hello ${param.name}!
</c:if>
--%>

</body>
</html>

[此贴子已经被作者于2006-12-23 20:54:45编辑过]

14 回复
#2
千里冰封2006-12-23 21:15
你的数据库里面有几条记录
#3
smoon2006-12-23 23:33

3条。。。。大家看看是代码的问题还是那的问题。。。

[此贴子已经被作者于2006-12-23 23:36:02编辑过]

#4
千里冰封2006-12-24 09:26

<td><img src="images/dot.gif" height=13 width=<%=r.getString("nume")%>></td>
除了这里加个引号外,其它没发现什么问题

#5
JavaEE52006-12-24 10:35
有没有双引号都一样

为什么不循环,你自己查查咯
select * from music where nume>0 order by nume desc
nume>0的记录是不是只有一条呀?
#6
千里冰封2006-12-24 11:45
好一个JavaEE5
#7
smoon2006-12-24 13:14

不是。。。在查询分析器里看拉。。。。还是3条呀。。。
真的没问题???。。我再看看去。。。

#8
smoon2006-12-24 13:24
在while前面加了2个r.next可以看到最后面的哪个投票结果。。。不过还是只有一条。。。。。。。。郁闷呀。。到底是那的错??

[此贴子已经被作者于2006-12-24 13:25:37编辑过]


#9
JavaEE52006-12-24 13:29
catch(Exception e){
out.print(e.ToString())
}

加个这个,看看有没有错
#10
smoon2006-12-24 13:41
java.sql.SQLException: No data found   为什么呀??查询分析器里有的呀。。。要是把next直接只到地2,3条也是可以输出的呀。。。。。不过还是只有1条。。。
#11
JavaEE52006-12-24 13:48

<%
string str_nume="";
while(r.next()){
str_nume=r.getString("nume"); //By the way,nume是字符串类型的吗?
%>


<tr>
<td><%=r.getString("musicname")%></td>
<td><img src=images/dot.gif height=13 width=<%=str_nume%>></td>
<td><%=str_nume%></td>
</tr>


<% }%>

#12
千里冰封2006-12-24 13:50

用JDBC:ODBC数据源的话,是不能重复得到一个列两次的,甚至不能先访问后面的列,后访问前面的列



建议你用JDBC驱动来直连,这样就好了

#13
JavaEE52006-12-24 13:59
哦~~原来如此。。。感谢老千
#14
smoon2006-12-24 14:09
我去试试。。有什么问题再找大家帮忙。。。
#15
smoon2006-12-24 14:18

谢谢2位拉。。。。问题解决拉哈哈。。

[此贴子已经被作者于2006-12-24 14:25:51编辑过]

1