JSP :while (rs.next()) 第一行数据显示不出。 jsp代码如下:
来源:百度知道 编辑:UC知道 时间:2024/05/24 04:59:40
<table width="257" border="1" align="center" cellpadding="1" cellspacing="1">
<tr>
<td height="29" colspan="2" align="center">投票结果</td>
</tr>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:shiyanshi","","");
Statement stmt = conn.createStatement();
String sql = "select Name,Vote from Vote";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
%>
<tr>
<td width="93" height="35"><%=rs.getString("Name")%></td>
<td width="151"><%=rs.getString("Vote")%></td>
</tr>
<%
}
rs.close();
stmt.close();
con
<tr>
<td height="29" colspan="2" align="center">投票结果</td>
</tr>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:shiyanshi","","");
Statement stmt = conn.createStatement();
String sql = "select Name,Vote from Vote";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next())
{
%>
<tr>
<td width="93" height="35"><%=rs.getString("Name")%></td>
<td width="151"><%=rs.getString("Vote")%></td>
</tr>
<%
}
rs.close();
stmt.close();
con
lz的写法没错,
ls的写法没有数据会抛空指针.
再找找其他原因,或者不在dreamweaver中预览,直接用浏览器预览看看.
[补充:] 调试jsp最好还是在浏览器下吧,,我是没有在dreamweaver下编辑过,不习惯,我一般用UE编辑jsp的..
这个可能是dreamweaver的bug,和你的代码没有关系.
do
{
%>
<tr>
<td width="93" height="35"><%=rs.getString("Name")%></td>
<td width="151"><%=rs.getString("Vote")%></td>
</tr>
<%
} while(rs.next());
因为你的第一行被“next”了
用do while
应该不是代码的问题,你再刷新下数据库看是不是第一行记录到底存不存在,或者浏览器中调试看看,数据库支持的话在数据库里直接select 语句查询看看
你到数据库中看一下第一行记录有没在先?
do while not rs.eof
怎样将Do While Not rs.EOF循环7行
[JSP]如何在For中,中断While的循环?
请教一个jsp里的if和while问题
Do While Not rs.EOF循环以N行3列显示该怎么解决?
ASP高手.帮忙在while not rs.eof 加个递加给我调用~
ASP高手.帮忙在while not rs.eof ..加个递加
在asp中的rs.fields.count和rs.fields(i).name在jsp中应该怎么表达啊?
jsp操作数据库的问题 重复出现<%=rs.getInt("ID")%>出错
jsp连接ACCESS中的 ResultSet rs=sqlStatement.executeQuery(SQL);是什么意思啊???