我在一个页面里添加了个链接到另一个页面,用来显示数据库里某个商品条目的详细信息。运行后提示有[Microsoft][SQLServer 2000 Driver for JDBC]Invalid operation for the current cursor position.错误,这是为什么?我应该怎么改?
我的程序如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="databean" scope="session" class="com.conndb"/>
<jsp:useBean id="list" class="com.WaresList" scope="session" />
<jsp:useBean id="pagebean" scope="session" class="com.pagebean"/>
<html>
<head>
<title>商品详细信息</title>
<style type="text/css">
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head>
<script language="javascript">
</script>
<body background="D:\Tomcat\Tomcat 5.0\webapps\ROOT\jing\picture\back2.bmp">
<div align="center" class="b9b">商品详细信息
<p>
<form action="shopcart.jsp" method="post" name="form1">
<%
String Id=request.getParameter("Id");
ResultSet rs=null;
String sql="SELECT * FROM wares where Id='"+Id+"'";
databean.getConnection();
rs=databean.executeQuery(sql); //执行sql语句,使用了javabean conndb中的executeQuery
rs.next();
%>
<input type=hidden name="id" value="<%=rs.getString("Id")%>" >
<table width="300" border="1" cellspacing="1" cellpadding="1" bordercolordark="#6699ff" bordercolorlight="#FFFFFF">
<tr>
<th colspan="2" scope="col"><img src="<%= rs.getString("BigImg") %>"></th>
</tr>
<tr>
<th width="65" scope="row">商品名称</th>
<th width="222" scope="row"><%=rs.getString("Name") %></th>
</tr>
<tr>
<th scope="row">所属种类</th>
<th scope="row"><%=rs.getString("Sort")%></th>
</tr>
<tr>
<th scope="row">市场价</th>
<th scope="row"><%= rs.getString("MarketPrice") %></th>
</tr>
<tr>
<th scope="row">当前价格</th>
<th scope="row"><%=rs.getString("Price") %></th>
</tr>
<tr>
<th scope="row">商品介绍</th>
<th scope="row"><%=rs.getString("Description") %></th>
</tr>
</table>
<td width=40 height=30> </td>
<tr><td> </td>
<p>
</form>
</div>
</body>
</html>
----------------解决方案--------------------------------------------------------
databean.getConnection();
rs=databean.executeQuery(sql); //执行sql语句,使用了javabean conndb中的executeQuery
rs.next();
我觉得是这里有错误啊 databean到底是什么对象啊?
----------------解决方案--------------------------------------------------------
databean是在这里声明的<jsp:useBean id="databean" scope="session" class="com.conndb"/>
事先定义了个conndb.java连接数据库。
这里不对吗?应该怎么改呢?
我初学jsp很多地方弄不懂,望各位指点指点。。。
----------------解决方案--------------------------------------------------------
不是那个意思.
rs=databean.executeQuery(sql); 他的调用者应该是Statement对象吧.
Statement st=databean.getConnection();
rs=st.executeQuery(sql); //执行sql语句,使用了javabean conndb中的executeQuery
rs.next();
你的conndb.java是怎么写的我不知道 也可能是我理解有问题
----------------解决方案--------------------------------------------------------
真的很感谢你!
我的conndb.java是这样写的:
package com;
import java.sql.*;
public class conndb {
private Connection con;
private ResultSet rs;
public static Connection getConnection() throws SQLException {
try {
//连接MS SQL Server数据库
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
return null;
}
return DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=jing","sa","sa");
//设置连接的数据库名,登陆的用户名和密码
}
//执行SQL语句的查询操作
public ResultSet executeQuery(String sql) {
try {
con = conndb.getConnection();
Statement statement = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
rs = statement.executeQuery(sql);
}
catch(SQLException ex)
{
}
return rs;
}
//执行SQL语句的更新操作
public int executeUpdate(String sql)
{
int count = 0;
Statement stmt = null;
try
{
con = conndb.getConnection();
stmt = con.createStatement();
count = stmt.executeUpdate(sql);
}
catch(SQLException ex)
{
}
finally
{
try
{
if(stmt != null)
stmt.close();
if(con != null)
con.close();
}
catch(SQLException ex)
{
System.err.print(ex);
}
}
return count;
}
//释放数据集rs,关闭数据库连接
public void freeRs(ResultSet rs)
{
try
{
if(rs != null)
{
rs.close();
con.close();
}
}
catch(Exception e)
{
}
}
}
----------------解决方案--------------------------------------------------------