在配置tomcat6.0连接池时:出现了javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.dbUtil.DbUtil.getcon(DbUtil.java:21)
at com.dbUtil.T.main(T.java:11)
的错误:
下面是关于tomcat/conf/context.xml的配置:
- Java code
<Resource name="jdbc/sqlserver" auth="Container" type="javax.sql.DataSource" maxActive="50" maxIdle="30" maxWait="10000" logAbandoned="true" username="sa" password="SQL2005" driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver" url="jdbc:microsoft:sqlserver://localhost:1433;databasename=blog"/>
然后是web。xml的配置:
- XML code
<description>DBConnection</description> <res-ref-name>jdbc/sqlserver</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
- Java code
Context ctx = new InitialContext(); //获取连接池对象 DataSource dSource = (DataSource) ctx.lookup("java:comp/env/jdbc/sqlserver"); con = dSource.getConnection();
这行代码
------解决方案--------------------
你有没有把sqlserver的JDBC驱动包放到tomcat的lib目录下面?
------解决方案--------------------
那段<Resource... 的配置放在哪了,如果是eclipse工程,要放在META-INF目录下