Java Spring 管理的数据源连接到 MS Sql 服务器,使用域身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21029797/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring managed datasource connection to MS Sql server with Domain authentication
提问by Haeflinger
I am getting an error when trying to create a datasource connection to MS SQL server using JTDS driver within my Spring Config. I am using domain authentication from a non windows machine.
尝试使用 Spring Config 中的 JTDS 驱动程序创建到 MS SQL 服务器的数据源连接时出现错误。我正在使用来自非 Windows 机器的域身份验证。
ERROR:
错误:
Caused by: java.sql.SQLException: Login failed.
The login is from an untrusted domain and cannot be used with Windows authentication.
Spring-Datasource.xml:
Spring-Datasource.xml:
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="jdbc:jtds:sqlserver://MS_SERVER/ms_db;domain=myDomain;integrated security=false"/>
<property name="username" value="myUser"/>
<property name="password" value="myPassword"/>
</bean>
I can create the connection manually and works perfect like:
我可以手动创建连接并完美地工作,例如:
public static void main(String[] args) {
System.out.println("Starting Connection test");
Connection connection;
String url = "jdbc:jtds:sqlserver://MS_SERVER/ms_db;domain=myDomain;integrated security=false";
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
connection = DriverManager.getConnection(url, "myUser","myPassword"));
System.out.println("Connection successful");
}
catch (Exception e) {
System.err.println("Cannot connect to database server");
e.printStackTrace();
}
}
Any suggestions would be appreciated
任何建议,将不胜感激
采纳答案by limc
Try this:-
尝试这个:-
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/>
<property name="url" value="jdbc:jtds:sqlserver://MS_SERVER/ms_db;domain=myDomain;integrated security=false"/>
<property name="username" value="myUser"/>
<property name="password" value="myPassword"/>
</bean>
Dependency for DBCP:-
DBCP 的依赖:-
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>