tomcat7配置SQLServer2005数据源无法获取连接,求大神指导!!
环境:Myeclipse2013、tomcat7、sqlserver20051.配置tomcat:conf/context.xml中<Context>标签内加入:<Res...
环境:Myeclipse2013、tomcat7、sqlserver2005
1.配置tomcat:
conf/context.xml中<Context>标签内加入:
<Resource name="jdbc/test"
auth="Container"
type="javax.sql.DataSource"
driverclassname="com.microsoft.sqlserver.jdbc.SQLServerDriver"
username="sa"
password="123"
url="jdbc:sqlserver://localhost:1433;databaseName=test"
maxActive="100"
maxIdle="30"
maxWait="5000"/>
2.将sqlserverjdbc驱动包放入apache-tomcat-7.0.39\lib目录
(WEB-INF/lib中也试过了)(驱动包已经测试通过)
3.修改web.xml,加入如下配置
<resource-ref>
<description>SQL DataSource</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4.java代码中通过数据源获取连接
public class DataSourceUtil {
private static DataSource ds = null;
public static Connection getConnection() {
Connection conn = null;
if (ds == null) {
Context ctx = null;
try {
ctx = new InitialContext();
} catch (NamingException e) {
System.out.println("创建InitialContext命名异常!");
}//end of try
try {
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
} catch (NamingException e) {
System.out.println("获取数据源命名异常!");
}//end of try
}//end of if
try {
conn = ds.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}//end of getConnection
}
6.“ds.getConnection()”打印错误如下:
org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create JDBC driver of class '' for connect URL 'jdbc:sqlserver://localhost:1433;databaseName=test'
Caused by: java.sql.SQLException: No suitable driver 展开
1.配置tomcat:
conf/context.xml中<Context>标签内加入:
<Resource name="jdbc/test"
auth="Container"
type="javax.sql.DataSource"
driverclassname="com.microsoft.sqlserver.jdbc.SQLServerDriver"
username="sa"
password="123"
url="jdbc:sqlserver://localhost:1433;databaseName=test"
maxActive="100"
maxIdle="30"
maxWait="5000"/>
2.将sqlserverjdbc驱动包放入apache-tomcat-7.0.39\lib目录
(WEB-INF/lib中也试过了)(驱动包已经测试通过)
3.修改web.xml,加入如下配置
<resource-ref>
<description>SQL DataSource</description>
<res-ref-name>jdbc/test</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
4.java代码中通过数据源获取连接
public class DataSourceUtil {
private static DataSource ds = null;
public static Connection getConnection() {
Connection conn = null;
if (ds == null) {
Context ctx = null;
try {
ctx = new InitialContext();
} catch (NamingException e) {
System.out.println("创建InitialContext命名异常!");
}//end of try
try {
ds=(DataSource)ctx.lookup("java:comp/env/jdbc/test");
} catch (NamingException e) {
System.out.println("获取数据源命名异常!");
}//end of try
}//end of if
try {
conn = ds.getConnection();
} catch (SQLException e) {
e.printStackTrace();
}
return conn;
}//end of getConnection
}
6.“ds.getConnection()”打印错误如下:
org.apache.tomcat.dbcp.dbcp.SQLNestedException:
Cannot create JDBC driver of class '' for connect URL 'jdbc:sqlserver://localhost:1433;databaseName=test'
Caused by: java.sql.SQLException: No suitable driver 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询