tomcat 7 mssql连接错误

时间:2015-03-10 18:12:08

标签: java sql-server tomcat

我在tomcat / lib中有tomcat 7,Java 1.7,sqljdbc.jar并尝试连接MSSQL数据库。我用JDBC连接测试了数据库,它工作得很好。当我尝试使用tomcat配置时,我收到了零点错误。

META-INF / context.xml中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<Context antiJARLocking="true" path="/APP_NAME">
<Resource name="jdbc/dbName" auth="Container"
    factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
    driverclassname="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    maxactive="10" maxidle="3" maxwait="10000" username="user"
    password="password" type="javax.sql.DataSource"
    url="jdbc:sqlserver://url;instanceName=myInstance;databaseName=dbName"
    removeAbandoned="true" removeAbandonedTimeout="30" logAbandoned="true">
</Resource>

我的web.xml

<resource-ref>
    <res-ref-name>jdbc/dbName</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

我正在测试与

的连接
@ManagedBean(name = "userDAO")
@SessionScoped
public class UserDAO {

@Resource(name="jdbc/AcapsRepo")
private DataSource ds;
public List<UserBean> getData() throws SQLException {
    Connection con = ds.getConnection();

并抛出错误

Exception in thread "main" java.lang.NullPointerException
at com.jpmc.acaps.repo.UserDAO.getData(UserDAO.java:37)
at com.jpmc.acaps.repo.UserDAO.main(UserDAO.java:120)

0 个答案:

没有答案