
tomcat配置sql server2005连接池
我在context.xml中写入<Contextreloadable="true"crossContext="true"> <Resource...
我在context.xml中写入<Context reloadable="true" crossContext="true"> <Resource name="jdbc/chat" auth="Container" type="javax.sql.DataSource" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://localhost:1433;DataBaseName=db_login" username="sa" password="123456" maxActive="100" maxIdle="30" maxWait="1000"/></Context>在web.xml中加入<resource-ref> <description>chat</description> <res-ref-name>jdbc/chat</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref> 然后数据库连接写public Connection getConnection() throws SQLException { Connection con =null; try { Context ctx = new InitialContext(); DataSource source=(DataSource)ctx.lookup("java:comp/env/jdbc/chat"); //Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); con = source.getConnection(); } catch (NamingException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } return con; } 但是我运行程序的时候会出现Cannot load JDBC driver class 'com.microsoft.sqlserver.jdbc.SQLServerDriver'错误
展开
展开全部
你把 SQLServer 的驱动程序包 .jar 要放在 tomcat/lib下,或tomcat/webapps/yourApp/WEB-INF/class/lib 下,否则它找不到驱动程序
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询