紧急求救:连接池问题,tomcat4.1+sql server 2000

zbcomn 2004-03-03 11:36:17
我参考了很多相关的文章,下边是我的做法,调用数据库的页面的错误提示是:[Microsoft][SQLServer 2000 Driver for JDBC]Unsupported method: ResultSet.last说我的不支持last,可是我要用到啊!

比较长,希望高手,好好看看!谢谢了
我的连接池的配置方法:

1、修改Tomcat 4.1\conf\server.xml,添加上
<Context path="/web" docBase="web" debug="0" reloadable="true">
<Resource name="jdbc/SqlServerDB" auth="Container" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/SqlServerDB">
<parameter>
<name>factory</name>

<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
</parameter>
<parameter>
<name>driverClassName</name>

<value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
</parameter>
<parameter>
<name>url</name> <value>jdbc:microsoft:sqlserver://127.0.0.1:1433;databaseName=jinweb</value>
</parameter>
<parameter>
<name>username</name>
<value>sa</value>
</parameter>
<parameter>
<name>password</name>
<value></value>
</parameter>
<parameter>
<name>maxActive</name>
<value>100</value>
</parameter>
<parameter>
<name>maxIdle</name>
<value>30</value>
</parameter>
<parameter>
<name>maxWait</name>
<value>10000</value>
</parameter>
</ResourceParams>
</Context>


2、修改Tomcat 4.1\webapps\web\WEB-INF\web.xml
添加上
<resource-ref>
<description>SqlServer Datasource example</description>
<res-ref-name>jdbc/SqlServerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

3、在Tomcat 4.1\webapps\web\WEB-INF\classes下编写链接数据库的文件DataBaseService.java并编译,内容如下:
package util;
import java.sql.*;
import javax.naming.*;
public class DataBaseService {
public DataBaseService() {
}

//获取测试字符串
public String getString()
{
return "shit !@#$%^&*())(*&^%$#@#$%^& shit";
}
//获取数据库连接
static Connection pobjConn = null;
static Statement pobjStmt = null;
public Connection getSqlConn() throws Exception
{
//使用连接池连接
Context pobjInitialContext = new InitialContext();
Context pobjContext = (Context) pobjInitialContext.lookup("java:comp/env");
Object pobjObject = (Object) pobjContext.lookup("jdbc/SqlServerDB");
javax.sql.DataSource pobjDataSource = (javax.sql.DataSource)pobjObject;
pobjConn = pobjDataSource.getConnection();
return pobjConn;

//使用驱动程序连接
/*
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=Bruce";
String user="sa";
String password="123";
pobjConn= DriverManager.getConnection(url,user,password);
return pobjConn;
*/
}

//获取查询数据库的结果集
public ResultSet executeQuery(String mstrMySql) throws Exception
{
pobjConn=getSqlConn();
pobjStmt = pobjConn.createStatement();
ResultSet rs=pobjStmt.executeQuery(mstrMySql);
return rs;
}
//存储过程的调用
public ResultSet executeProc(int pintParam) throws Exception
{
pobjConn=getSqlConn();
ResultSet rs=null;
try
{
CallableStatement pobjCallStmt = pobjConn.prepareCall("{call testProc(?)}");
pobjCallStmt.setInt(1,pintParam);
rs=pobjCallStmt.executeQuery();
}
catch(Exception err)
{
throw err;
}
return rs;
}
//执行数据库更新操作
public boolean executeUpdate(String mstrMySql) throws Exception
{
try
{
pobjConn = getSqlConn();
pobjStmt = pobjConn.createStatement();
pobjStmt.executeUpdate(mstrMySql);
return true;
}
catch(Exception er)
{
throw er;
}
}}


4、调用数据库的页面加上
<jsp:useBean id="RegisterBean" class="util.DataBaseService" />





...全文
19 4 点赞 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-03-03 11:36
社区公告
暂无公告