运行在Window服务器上的Java应用程序是否可以通过Windows身份验证连接到SQL Server [英] Can a Java application running on a Window's Server connect to SQL Server via Windows Authentication

查看:320
本文介绍了运行在Window服务器上的Java应用程序是否可以通过Windows身份验证连接到SQL Server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我提出问题之前,请先给我一些背景知识。我在一家主要经营Windows的商店。我们在Windows服务器上运行了几个批处理应用程序(主要是2003)。大多数批处理应用程序都是用C#和C ++编写的;但是我们有一些用Java编写的应用程序。

Let me give some background before I ask my question. I’m at a shop that primarily runs Windows. We have several batch applications running on Windows Servers (mostly 2003). Most of these batch applications are written in C# and C++; however we have a handful of applications that are written in Java.

批处理Java应用程序使用JDBC连接到SQL Server 2005数据库。请注意我们没有使用应用程序服务器。

The batch Java applications are connecting to a SQL Server 2005 database using JDBC. Please note we are not using an application server.

目前,我们在Windows注册表中存储数据库连接信息(数据库,用户名和密码)。

Currently we store database connection information (database, username, & password) in the Windows Registry.

不幸的是,这些真正不友好的审核员(对幽默的不良尝试)对我们在Windows注册表中存储数据库连接信息的决定感到不满意。
我们现在正在使用Windows Authentatication更新我们的批处理应用程序以连接到SQL Server。

Unfortunately these really unfriendly auditors (bad attempt at humor) are not happy with us over the decision to store database connection information in the Windows registry. We are now updating our batch applications to connect to SQL Server using Windows Authentatication.

对C#和C ++应用程序使用Windows身份验证不是问题。但是我坚持要求Java应用程序。

Using Windows Authentatication for C# and C++ applications is not a problem; however I’m stuck on the direction to take for the Java applications.

有人可以建议是否可以使用Windows Authentatication从Windows服务器上运行的Java批处理应用程序连接到SQL Server 2005数据库?我们再次使用的是应用服务器。

Can anyone advise if it is possible to use Windows Authentatication to connect to a SQL Server 2005 database from a Java batch application running on a Windows server? Again we are not using an application server.

如果可能,您推荐的方法是什么?

If this is possible what are your recommended approaches?

我有一个简单的加密密码的策略,这将使审核员满意,但是我希望我的所有批处理应用程序都通过Windows Authentatication连接到SQL Server。

I have a strategy to simply encrypt the password which will make the auditors happy, however I would prefer to have all of my batch applications connect to SQL Server via Windows Authentatication.

推荐答案

您可以使用Windows身份验证从Java程序连接到SQL Server,如下所示:

You can connect to SQL Server from Java programs using windows authentication as follows:


  1. 为将用于运行程序的应用程序创建一个Windows帐户。此帐户的凭据将用于连接到服务器。

  2. here

  3. 按如下方式配置JDBC URL:

  1. Create a windows account for the application that would be used to run your programs. This account's credentials will be used to connect to the server.
  2. Get Microsoft JDBC Driver for SQL Server from here.
  3. Configure the JDBC URL as follows:

jdbc:sqlserver://<hostname>;databaseName=<DBName>;integratedSecurity=true


  • 从命令行配置运行Java程序的启动程序,以包含以下JVM参数:

  • Configure the launcher that run the Java programs from command line to include the following JVM parameter:

    -Djava.library.path="<jdbc driver dll location>"
    

    其中location是安装或提取先前下载的JDBC驱动程序的目录。在我的情况下,它是 C:\Program Files \sqljdbc_4.0.2206.100_enu\sqljdbc_4.0\enu\auth\x64 。正如Luke Woodward在评论中提到的,应该根据用于运行这些程序的JVM选择dll。

    where the location is the directory where the JDBC driver downloaded earlier is installed or extracted. It was C:\Program Files\sqljdbc_4.0.2206.100_enu\sqljdbc_4.0\enu\auth\x64 in my case. As Luke Woodward mentioned in the comments, the dll should be picked based on the JVM used for running these programs.

    使用上述配置,建立到SQL Server的连接将使用运行java程序/进程的域用户的Windows身份验证凭据。

    With the above configuration, the connection established to SQL Server would use the Windows Authentication Credentials of the domain user running the java program/process.

    这篇关于运行在Window服务器上的Java应用程序是否可以通过Windows身份验证连接到SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆