免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2239 | 回复: 2
打印 上一主题 下一主题

配置jndi的问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-01-24 17:06 |只看该作者 |倒序浏览
server.xml中
<Context>;
...
<Resource name="jdbc/Test" auth="Container" type="javax.sql.DataSource"/>;
<ResourceParams name="jdbc/Test">;
      <parameter>;<name>;user</name>;<value>;root</value>;</parameter>;
      <parameter>;<name>;password</name>;<value>;root123</value>;</parameter>;
      <parameter>;<name>;driverClassName</name>;
              <value>;org.gjt.mm.mysql.Driver</value>;</parameter>;
      <parameter>;<name>;driverName</name>;
              <value>;jdbc:mysql://localhost/test</value>;</parameter>;
</ResourceParams>;
...
</Context>;
web.xml中
<resource-ref>;
  <description>;。。。</description>;
  <res-ref-name>;
    jdbc/Test
  </res-ref-name>;
  <res-type>;
    javax.sql.DataSource
  </res-type>;
  <res-auth>;
    Container
  </res-auth>;
</resource-ref>;

test.jsp中
<%@ page import="javax.naming.Context" %>;
<%@ page import="javax.sql.DataSource"%>;
<%@ page import="javax.naming.InitialContext"%>;
<%@ page import="java.sql.*"%>;

<%
   DataSource ds = null;
   try{
     Context initCtx = new InitialContext();
     Context envCtx = (Context) initCtx.lookup("java:comp/env";
     ds = (DataSource)envCtx.lookup("jdbc/Test";
if(ds!=null)
{
  out.println("Connection is OK!<br>;";
  Connection con=ds.getConnection();
  con.close();
}
else
out.println("Fail!";
   }
                catch(SQLException e){ out.println(e);}
                catch(Exception ne){ out.println(ne);}
%>;
运行以后:
Connection is OK!
java.sql.SQLException: Cannot create JDBC driver of class 'org.gjt.mm.mysql.Driver' for connect URL 'null'
说明DataSource对象正确建立了
为什么Connection对象未能成功建立?

论坛徽章:
0
2 [报告]
发表于 2003-01-24 17:21 |只看该作者

配置jndi的问题!

冷清!

论坛徽章:
0
3 [报告]
发表于 2003-02-05 10:11 |只看该作者

配置jndi的问题!

你的平台是什么?如果是Apache+tomcat4.1,把JDBC驱动考到%Tomcat_Home%/common/lib目录下,不能考到其他目录,我的配置经验。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP