开发者

Exception while creating mssql database jndi resource in Tomcat

I am trying to create a Tomcat JNDI resource for MSSQL database.

This is how my resource string looks in tomcat context.xml file

  <Resource 
    name="jdbc/FI/SD" 
    auth="Container" 
    type="javax.sql.DataSource"
    driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" 
    url="jdbc:sqlserver://LDIA;databaseName=SD"     
    validationQuery="Select 1"
    maxActive="1" maxIdle="1" maxWait="10000"
    user="rels"
    password="hidden" 
  />

This is the code snippet that i am using in Servlet to check datasource:

   Context initCtx = new InitialContext();
   Context envCtx = (Context) initCtx.lookup("java:comp/env");
   DataSource ds = (DataSource)envCtx.lookup("jdbc/FI/SD");
   Connection conn = ds.getConnection();

but i am getting this error while creating connection at line 4, how can i solve this:

    org.apache.tomcat.dbcp.dbcp.SQLNestedException: 
Cannot create PoolableConnectionFactory (Login failed for user ''. The user is not associated with a trusted SQL Server connection.)
            at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549)
            at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
            at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
            at com.MyServlet.doGet(MyServlet.java:40)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
            at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
            at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            at org.apache.catalina.core.St开发者_JS百科andardWrapperValve.invoke(StandardWrapperValve.java:233)
            at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)


Maybe user should be username instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜