我已经使用 java 中的 persistence.xml
建立了与 mssql 的连接。为此,我必须将 sqljdbc_auth.dll 复制到 system32 中,因为我想使用 Windows 身份验证进行连接。有没有办法在不复制dll文件的情况下达到相同的结果?删除 dll 会导致此警告并阻止执行:
Failed to load the sqljdbc_auth.dll cause : no sqljdbc_auth in java.library.path
这就是我的坚持:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="migration">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>migration.xcs.model.Kennzahl</class>
<properties>
<property name="javax.persistence.jdbc.driver"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="javax.persistence.jdbc.url"
value="jdbc:sqlserver://localhost:1433;databaseName=kendb;integratedSecurity=true;" />
<property name="hibernate.archive.autodetection" value="class" />
</properties>
</persistence-unit>
这些是我的 pom 依赖项:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.0.5.Final</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
最佳答案
您尚未添加 sqljdbc_auth.dll
所在的路径。
找出系统中 DLL 的位置并将其添加到您的类路径
中。
或者在 Eclipse 中,您可以像这样运行配置
:
-Djava.library.path=C:\path of the dll\
关于java - 通过持久性连接到mssql而不复制dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34613619/