很郁闷...我搞了一个星期都搞不好.. 网上的不是少了一点,就是copy and paste人家的.. 今日跟住网上一篇文章做了一下.. 我用的是tomcat-5.5.23 和sql server 2005 我先再%tomcat_home%/common/lib中加入SQL2005的JDBC DRIVER
然后在%tomcat_home%/conf/server.xml </host> 里 加入 <Context path="/AVG" docBase="AVG" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/avg" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="chessman_mak" password="chessman"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost"/>
<ResourceLink global="jdbc/avg" name="jdbc/avg" type="javax.sql.DataSource"/>
</Context>然后在项目的web-inf下的web.xml里加入<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/avg</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>在测试中..我用这三句来连接InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/avg");但是..还是出错了... org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'网上说吧DRIVER入进COMMON/LIB中就OK了. . 但是我还是遇到这个问题了. . 郁闷请大侠们教教我吧..
谢谢..
然后在%tomcat_home%/conf/server.xml </host> 里 加入 <Context path="/AVG" docBase="AVG" debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/avg" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="chessman_mak" password="chessman"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost"/>
<ResourceLink global="jdbc/avg" name="jdbc/avg" type="javax.sql.DataSource"/>
</Context>然后在项目的web-inf下的web.xml里加入<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/avg</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>在测试中..我用这三句来连接InitialContext initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/avg");但是..还是出错了... org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'网上说吧DRIVER入进COMMON/LIB中就OK了. . 但是我还是遇到这个问题了. . 郁闷请大侠们教教我吧..
谢谢..
解决方案 »
- mysql的中文乱码问题
- 关于 网站页面程序的优化
- 请教关于tomcat+eclipse的问题
- jsp:图片插入mysql数据库?
- 请问关于struts的问题
- 怪现象,请高手帮忙找原因.................
- JAVA如何读word的doc文档!谢谢!
- 假设只能通过VC编程,并给出串口、网口、USB口,声卡Mic口等端口及连接电缆,简述如何实现在两台计算机之间传送一个数据文件。
- weblogic部署问题,安装时提示无法访问所选应用程序
- 谁知道那有VISUALAGE最高版本下载?一定给分
- Struts+DAO做登录验证,prepareStatement抛出异常
- java程序员必看的面试题 2
<Resource name="jdbc/avg" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="chessman_mak" password="chessman"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://localhost"/> 加在 server.xml里的 <GlobalNamingResources> 中 有些说加在<host>中.. 那个才对呢??
-------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/myjsp" URIEncoding="UTF-8">
<Resource name="jdbc/myjdbc"
auth="Container"
description="DB Connection"
driverClassName="com.mysql.jdbc.Driver"
maxActive="500"
maxIdle="30"
maxWait="10000"
type="javax.sql.DataSource"
username="user1"
password="123456"
url="jdbc:mysql://localhost:3306/mydb?autoReconnect=true"
/>
</Context>
=====================================================
win.xml
----------------------------------------------------------------------
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myjdbc</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Statement stmt;
ResultSet rs;try
{
Context ctx = new InitialContext ();
DataSource ds = (DataSource) ctx.lookup ("java:comp/env/jdbc/myjdbc");
con = ds.getConnection ();
stmt = con.createStatement ();
String SqlCmdText = String.format (" ...... // 你的 SQL int i = stmt.executeUpdate (SqlCmdText); // 执行 insert update 等
// 或者
rs = stmt.executeQuery(SqlCmdText); // select ,带反馈结果的使用方法
SQL2005 还有个问题,默认并没有开启 TCP 连接,只支持管道命名,所以需要在配制里启动TCP连接方式,再重新启动数据库<?xml version="1.0" encoding="UTF-8"?>
<Context path="/openinfo" URIEncoding="UTF-8">
<Resource
description="DB Connection"
driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
maxActive="500"
maxIdle="30"
maxWait="10000"
name="jdbc/myjdbc"
auth="Container"
type="javax.sql.DataSource"
username="user1"
password="123456"
url="jdbc:sqlserver://localhost:1433;databaseName=MyDB"
/>
</Context>
楼上, 我根据你的方式改了也不行... 555 我郁闷死了.. 你说TCP连接方式 ??? ..... 是什么东东?? 怎样改?
郁闷好多天了