tomcat数据库连接池出现异常

来源:百度知道 编辑:UC知道 时间:2024/06/11 00:35:40
我是按照v512高端JAVA视频上的配置的。
1、先修改tomcat5.5/conf/content.xml,我加上了如下代码:
<Resource name="jdbc/mysqlds" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30"
maxWait="10000" username="root" password="56906950" driverClassName="com.mysql.jdbc.Dirver"
url="jdbc:mysql://127.0.0.1:3333/music" />

2、然后再项目中引用:
Context context=new InitialContext();
DataSource ds=(DataSource)context.lookup("java:/comp/env/jdbc/mysqlds");
conn=ds.getConnection();

然后启动tomcat服务器,但是用测试JAVA类测试连接的时候,出现异常:
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

谢谢高手指教啊
视频上没有配置web.xml,mysql的驱动有放在了tomcat/common/lib下面

配置了web.xml了么

<resource-ref>
<description>mysqlds</description>
<res-ref-name>jdbc/mysqlds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>

web-inf里面的web.xml

第一步,把驱动有放在了tomcat/common/lib下面,第二步修改tomcat/conf/context.xml。 代码如下
<Resource name="jdbc/bank" auth="Container"
type="javax.sql.DataSource" maxActive="100"
maxIdle="30" maxWait="10000" username="sa"
password="sa"
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=bank"
/>
然后带连接类里 Context ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup("java:comp/env/jdbc/food");

co