欢迎来到天天文库
浏览记录
ID:34772657
大小:110.18 KB
页数:12页
时间:2019-03-10
《数据库连接池的datasourceds》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、数据库连接池的DataSourceds=(DataSource)ctx.lookup(ds)出错浏览次数:325次悬赏分:0
2、提问时间:2010-11-714:26
3、提问者:goshineverDataSourceds=(DataSource)ctx.lookup(ds);一直出现Themethodlookup(Name)inthetypeContextisnotapplicableforthearguments(DataSource)错误。下面是我的java代码和数据源的配置packagestore;
4、importjava.sql.*;importjavax.naming.*;importjavax.sql.DataSource;publicclassDBConn{privateStringds="jdbc/store";privateConnectionconn;publicDBConn(){try{ContextinitCtx=newInitialContext();Contextctx=(Context)initCtx.lookup("java:comp/env");DataSourceds=(
5、DataSource)ctx.lookup(ds);conn=ds.getConnection();}catch(Exceptione){System.out.print(e.toString());}}publicsynchronizedStatementgetStmt()throwsException{Statementstmt;stmt=conn.createStatement();returnstmt;}publicsynchronizedPreparedStatementgetPstmt(St
6、ringsql)throwsException{PreparedStatementpstmt;pstmt=conn.prepareStatement(sql);returnpstmt;}publicsynchronizedResultSetquery(Stringsql)throwsException{try{Statementstmt;stmt=conn.createStatement();ResultSetrs=stmt.executeQuery(sql);returnrs;}catch(Excep
7、tione){System.out.print(e.toString());returnnull;}}publicsynchronizedintupdate(Stringsql)throwsException{intnn;try{Statementstmt;stmt=conn.createStatement();nn=stmt.executeUpdate(sql);}catch(Exceptione){System.out.print(e.toString());nn=0;}returnnn;}publ
8、icvoidDBclose()throwsSQLException{if(rs!=null)rs.close();if(pstmt!=null)pstmt.close();if(stmt!=null)stmt.close();}}tomcat中serve.xml中配置9、ord="gu19901230"driverClassName="com.mysql.jdbc.Driver"maxIdle="1000"maxWait="5000"url="jdbc:mysql://localhost:3306/store?characterEncoding=GBK"maxActive="30"/>项目web.xml中配置DBConnectionjdbc/10、storejavax.sql.DataSourceContainer就是不知道这是倒是是咋回事,求高手解答推荐答案publicclassDBI{privatestaticDBIdbi=newDBI();privatestaticDataSourceds=null;publicstaticDBIget
9、ord="gu19901230"driverClassName="com.mysql.jdbc.Driver"maxIdle="1000"maxWait="5000"url="jdbc:mysql://localhost:3306/store?characterEncoding=GBK"maxActive="30"/>项目web.xml中配置DBConnectionjdbc/
10、storejavax.sql.DataSourceContainer就是不知道这是倒是是咋回事,求高手解答推荐答案publicclassDBI{privatestaticDBIdbi=newDBI();privatestaticDataSourceds=null;publicstaticDBIget
此文档下载收益归作者所有