我在将web应用程序从Tomcat 6迁移到WASLiber8.5.5.8时遇到了数据库连接问题。
关于“自由”,我得到了以下错误:
com.microsoft.sqlserver.jdbc.SQLServerException: This driver is not configured for integrated authentication我已经将"sqljdbc4.jar“放置在应用程序WEB\lib文件夹中。我尝试过将文件"sqljdbc_auth.dll“放置在不同的位置,比如applications WEB\ lib -文件夹、WEB文件夹、WEB文件夹。但这些都解决不了我的问题。
在Tomcat上,我在Tomcat文件夹中放置了"sqljdbc4.jar“,在Tomcat文件夹中放置了"sqljdbc_auth.dll”,然后它就工作了。
我怀疑我把"sqljdbc_auth.dll“文件放在了错误的位置,但我不知道还能把它放在哪里。我还没能在网上找到任何指定文件放在哪里的内容。
发布于 2015-12-21 15:04:48
首先,我建议您在应用程序中使用DataSource,而不是原始的JDBC驱动程序。通过使用DataSource (当在应用服务器上配置容器时对其进行管理),您将受益于应用服务器所做的许多固有的优化,例如连接池和事务支持。
请注意,DataSource并不是特定于WAS的,在任何应用服务器中,通过使用容器管理的DataSource而不是原始的JDBC驱动程序,您将以更低的开发成本获得更高的性能。
配置DataSource:
在DataSource和JDBC库中配置server.xml:
<!-- Enable JDBC and JNDI features (at least) -->
<featureManager>
<feature>jdbc-4.1</feature>
<feature>jndi-1.0</feature>
</featureManager>
<dataSource id="MyDataSource" jndiName="jdbc/MyDataSource">
<jdbcDriver libraryRef="MSJDBCLib"/>
<properties.microsoft.sqlserver databaseName="SAMPLEDB" serverName="localhost" portNumber="1433"/>
</dataSource>
<library id="MSJDBCLib">
<fileset dir="C:/path/to/sqljdbc4.jar"/>
<!-- To have authentication support, add the dll to the library -->
<fileset dir="C:/path/to/sqljdbc_auth.dll"/>
</library>参见IBM doc:在中配置数据库连接
回答问题的关键是添加指向<library>元素中的auth文件的<library>元素,如下所示:
<!-- To have authentication support, add the dll to the library -->
<fileset dir="C:/path/to/sqljdbc_auth.dll"/>使用:DataSource:
以前,你可能做过这样的事:
String connectionURL = "jdbc:sqlserver://localhost:1433;DatabaseName=YourDBName;user=UserName;Password=YourPassword";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(connectionUrl);使用DataSources,您可以使用JNDI注入它们或查找它们:
注射:
@Resource(lookup = "jdbc/MyDataSource")
DataSource myDataSource;
...
Connection con = myDataSource.getConnection();JNDI查询:
DataSource myDataSource = new InitialContext().lookup("jdbc/MyDataSource");
Connection conn = myDataSource.getConnection();https://stackoverflow.com/questions/34396553
复制相似问题