藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月6日 10:18


配置jndi的問題!

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對像未能成功建立?

配置jndi的問題!

冷清!

配置jndi的問題!

你的平台是什麼?如果是Apache+tomcat4.1,把JDBC驅動考到%Tomcat_Home%/common/lib目錄下,不能考到其他目錄,我的配置經驗。



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com