急,jsp和mysql的问题,

supercctv 2004-01-30 10:40:14
mysqltest.jsp

<%@ page contentType="text/html; charset=gb2312" %>

<html>
<head>
<title>JSPMySQL!</title>
</head>

<body>
<%@ page language="java" import="java.sql.*" %>
<jsp:useBean id="DBconn1" scope="page" class="Mysqltest.DBconn" />
<%
ResultSet RS = DBconn1.executeQuery("SELECT * FROM ipaddress where id='1'");
out.print("<h1>" + RS.getString("country")+"</h1>");
RS.close();
%>
</body>
</html>

===========================================
DBconn.java

package Mysqltest;
import java.sql.*;

public class DBconn
{
String DBDriver="org.gjt.mm.mysql.Driver";
String ConnStr="jdbc:mysql://localhost/ip";//Êý¾Ý¿âÃû
String MyUser="root";
String MyPassword="cctv.summer";
Connection conn = null;
ResultSet rs = null;

public DBconn
{
try
{
Class.forName(DBDriver);
}
catch(java.lang.ClassNotFoundException e)
{
System.err.println("DBconn (): " + e.getMessage());
}
}

public ResultSet executeQuery(String sql) {
rs = null;
try
{
conn = DriverManager.getConnection(ConnStr,MyUser,MyPassword);
Statement stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.err.println("aq.executeQuery:"+ex.getMessage());
}
return rs;
}
}



运行时提示
javax.servlet.ServletException: Before start of result set
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.mysqltest_jsp._jspService(mysqltest_jsp.java:73)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)



大家帮忙看看啦,谢谢了,
...全文
10 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
lhbf 2004-01-31
ResultSet RS = DBconn1.executeQuery("SELECT * FROM ipaddress where id='1'");
out.print("<h1>" + RS.getString("country")+"</h1>");
错误就出现在这里,其实错误提示的也是:在结果集开始以前。
所以,你只要把结果集的光标位置移动一下就可以了。
回复
lhbf 2004-01-31
你的结果集中的光标还没有移到记录上呢,在.jsp中用rs.next()或者rs.last()等移到有数据的行试试
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-01-30 10:40
社区公告
暂无公告