context.xml中
<Resource name="jdbc/guestbook"
auth="Container"
type="javax.sql.DataSource"
password="root"
username="root"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost/test"
maxActive="10"
maxIdle="4"
maxWait="5000"/>获取数据连接:
Context context = new InitialContext()
Datasource ds = context.lookup("java:comp/env/jdbc/guestbook");
Connection ct = ds.getConnection();抛出异常:
javax.naming.NameNotFoundException: Name guestbook is not bound in this Context
at ort.apache.naming.namingContext.lookup(NamingContext.java:770)
at ort.apache.naming.namingContext.lookup(NamingContext.java:140)
at ort.apache.naming.namingContext.lookup(NamingContext.java:781)
at ort.apache.naming.namingContext.lookup(NamingContext.java:153)
at ort.apache.naming.SelectorContext.lookup(NamingContext.java:137)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.wh
.guestbook.AddMessageServlet.update(AddMessageServlet.java:112)
...........................
<Resource name="jdbc/guestbook"
auth="Container"
type="javax.sql.DataSource"
password="root"
username="root"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost/test"
maxActive="10"
maxIdle="4"
maxWait="5000"/>获取数据连接:
Context context = new InitialContext()
Datasource ds = context.lookup("java:comp/env/jdbc/guestbook");
Connection ct = ds.getConnection();抛出异常:
javax.naming.NameNotFoundException: Name guestbook is not bound in this Context
at ort.apache.naming.namingContext.lookup(NamingContext.java:770)
at ort.apache.naming.namingContext.lookup(NamingContext.java:140)
at ort.apache.naming.namingContext.lookup(NamingContext.java:781)
at ort.apache.naming.namingContext.lookup(NamingContext.java:153)
at ort.apache.naming.SelectorContext.lookup(NamingContext.java:137)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.wh
.guestbook.AddMessageServlet.update(AddMessageServlet.java:112)
...........................
解决方案 »
- 为什么struts2上传得到的都是.tmp的文件
- A server error has occured.More information may be available in the console.
- 关于秒表的问题
- 又是一个无法解决的问题,绞尽脑汁啊
- Hibernate/JPA中关于数据库视图对应的配置
- 下载次数统计 目前也没有一个合理的解决方案
- J2EE和J2ME用什么开发工具比较好啊?
- 留言板,无法正常访问(netbeans)写的。。。需要调试一下
- jsp 怎么读写客户端文件!
- 我想用tomcat运行一个servlet程序,可不知道怎么设置web.xml
- struts乱码问题
- JSP开源的论坛或网站推荐
不同版本的server.xml配置有点区别!
建议,现在server.xml配置通过后再移植到context.xml里。
<resource-ref>
<description>MySql Connection</description>
<res-ref-name>jdbc/TestDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="jdbc/guestbook"
auth="Container"
type="javax.sql.DataSource"
password="root"
username="root"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost/test"
maxActive="10"
maxIdle="4"
maxWait="5000"/>
</Context>这样对不对!我也遇到过这样的异常,是我写错了<Context></Context>,试试.
<resource-ref>
<description>MySql Connection</description>
<res-ref-name>jdbc/guestbook</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
是和context.xml中一样的配置吗?
<Resource name="jdbc/guestbook"
auth="Container"
type="javax.sql.DataSource"
password="root"
username="root"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost/test"
maxActive="10"
maxIdle="4"
maxWait="5000"/> 获取数据连接:
Context context = new InitialContext()
Datasource ds = context.lookup("java:comp/env/jdbc/guestbook");
Connection ct = ds.getConnection();
web.xml中
<resource-ref>
<description>MySql Connection </description>
<res-ref-name>jdbc/guestbook </res-ref-name>
<res-type>javax.sql.DataSource </res-type>
<res-auth>Container </res-auth>
</resource-ref> 增加了这个还是同样的错误异常。
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test1?autoReconnect=true"/>貌似是你驱动版本太老了换我这个试试
initContext = new InitialContext();
Context envContext = (Context)initContext.lookup("java:/comp/env");
DataSource ds = (DataSource)envContext.lookup("jdbc/TestDB");
Connection conn = ds.getConnection();
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/test1?autoReconnect=true"/>