| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1282 人关注过本帖
标题:[求助]急求各位指点,关于[Microsoft][SQLServer 2000 Driver for JDBC]错误 ...
只看楼主 加入收藏
yinsu33
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-6-30
收藏
 问题点数:0 回复次数:4 
[求助]急求各位指点,关于[Microsoft][SQLServer 2000 Driver for JDBC]错误

我在一个页面里添加了个链接到另一个页面,用来显示数据库里某个商品条目的详细信息。运行后提示有[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>&nbsp;</td>
<tr><td>&nbsp;</td>
<p>
</form>
</div>
</body>
</html>

搜索更多相关主题的帖子: Microsoft Driver JDBC SQLServer 
2007-07-01 21:20
zhanglinkai
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2006-11-25
收藏
得分:0 
databean.getConnection();
rs=databean.executeQuery(sql); //执行sql语句,使用了javabean conndb中的executeQuery
rs.next();
我觉得是这里有错误啊 databean到底是什么对象啊?

希望自己能走的更远!!!
2007-07-01 21:27
yinsu33
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-6-30
收藏
得分:0 
databean是在这里声明的<jsp:useBean id="databean" scope="session" class="com.conndb"/>
事先定义了个conndb.java连接数据库。
这里不对吗?应该怎么改呢?
我初学jsp很多地方弄不懂,望各位指点指点。。。

2007-07-01 21:42
zhanglinkai
Rank: 1
等 级:新手上路
帖 子:87
专家分:0
注 册:2006-11-25
收藏
得分:0 
不是那个意思.
rs=databean.executeQuery(sql); 他的调用者应该是Statement对象吧.
Statement st=databean.getConnection();
rs=st.executeQuery(sql); //执行sql语句,使用了javabean conndb中的executeQuery
rs.next();
你的conndb.java是怎么写的我不知道 也可能是我理解有问题

希望自己能走的更远!!!
2007-07-01 22:02
yinsu33
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2007-6-30
收藏
得分:0 

真的很感谢你!
我的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)
{
}
}
}


2007-07-01 22:10
快速回复:[求助]急求各位指点,关于[Microsoft][SQLServer 2000 Driver for JDB ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015672 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved