在命令行上确定SQL Server JDBC版本

时间:2022-06-11 08:24:00

I have several servers which use the Microsoft SQL Server JDBC driver. The files are all named sqljdbc4.jar. I need to know what version of the driver each one contains. Time stamps and file sizes are not helpful, as I need to extract the driver version number. I need to be able to run this on the command line.

我有几个使用Microsoft SQL Server JDBC驱动程序的服务器。这些文件都名为sqljdbc4.jar。我需要知道每个包含的驱动程序的版本。时间戳和文件大小没有帮助,因为我需要提取驱动程序版本号。我需要能够在命令行上运行它。

I have seen for DB2 you can run this command and get the version:

我见过DB2,你可以运行这个命令并得到版本:

java -cp ./db2jcc.jar com.ibm.db2.jcc.DB2Jcc -version

What is the equivalent, if any, for Microsoft SQL Server?

Microsoft SQL Server的等价物(如果有)是什么?

2 个解决方案

#1


2  

It seems that there is no dedicated CLI to print out the driver version but you can ask the MS 4.x driver for its version:

似乎没有专用的CLI来打印驱动程序版本,但您可以向MS 4.x驱动程序询问其版本:

import java.sql.Driver;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
...
Driver driver = new SQLServerDriver();
driver.getMajorVersion();  // -> 4
driver.getMinorVersion();  // -> 0, 1, 2, ...

You could build a simple commandline wrapper to print out this information.

您可以构建一个简单的命令行包装器来打印出这些信息。

#2


1  

IBM provides specific tooling in its JAR to provide for the behavior you describe. It is not a general feature of JDBC drivers or of JAR files.

IBM在其JAR中提供特定工具以提供您描述的行为。它不是JDBC驱动程序或JAR文件的一般功能。

Microsoft documents the available mechanisms for determining the driver version on MSDN. They offer two alternatives:

Microsoft记录了在MSDN上确定驱动程序版本的可用机制。他们提供两种选择:

  • extract the information from an [SQLServer]DatabaseMetaData object obtained via the driver (i.e. by a Java program); the most appropriate method for your use appears to be getDriverVersion(). Or
  • 从通过驱动程序获得的[SQLServer] DatabaseMetaData对象中提取信息(即通过Java程序);最适合您使用的方法似乎是getDriverVersion()。要么
  • extract the information from the readme.txt file provided in the distribution.
  • 从分发中提供的readme.txt文件中提取信息。

Unless readme.txt is packaged in the JAR (possible, but unlikely), the former approach is the only one that will work with the JAR file alone. It shouldn't be too hard to write a Java program and maybe a wrapper script to apply this approach to the task, but it doesn't look anywhere near as simple as for the DB2 driver.

除非将readme.txt打包在JAR中(可能但不太可能),否则前一种方法是唯一可以单独使用JAR文件的方法。编写Java程序并且可能是一个将这种方法应用于任务的包装器脚本应该不会太难,但它看起来并不像DB2驱动程序那么简单。

#1


2  

It seems that there is no dedicated CLI to print out the driver version but you can ask the MS 4.x driver for its version:

似乎没有专用的CLI来打印驱动程序版本,但您可以向MS 4.x驱动程序询问其版本:

import java.sql.Driver;
import com.microsoft.sqlserver.jdbc.SQLServerDriver;
...
Driver driver = new SQLServerDriver();
driver.getMajorVersion();  // -> 4
driver.getMinorVersion();  // -> 0, 1, 2, ...

You could build a simple commandline wrapper to print out this information.

您可以构建一个简单的命令行包装器来打印出这些信息。

#2


1  

IBM provides specific tooling in its JAR to provide for the behavior you describe. It is not a general feature of JDBC drivers or of JAR files.

IBM在其JAR中提供特定工具以提供您描述的行为。它不是JDBC驱动程序或JAR文件的一般功能。

Microsoft documents the available mechanisms for determining the driver version on MSDN. They offer two alternatives:

Microsoft记录了在MSDN上确定驱动程序版本的可用机制。他们提供两种选择:

  • extract the information from an [SQLServer]DatabaseMetaData object obtained via the driver (i.e. by a Java program); the most appropriate method for your use appears to be getDriverVersion(). Or
  • 从通过驱动程序获得的[SQLServer] DatabaseMetaData对象中提取信息(即通过Java程序);最适合您使用的方法似乎是getDriverVersion()。要么
  • extract the information from the readme.txt file provided in the distribution.
  • 从分发中提供的readme.txt文件中提取信息。

Unless readme.txt is packaged in the JAR (possible, but unlikely), the former approach is the only one that will work with the JAR file alone. It shouldn't be too hard to write a Java program and maybe a wrapper script to apply this approach to the task, but it doesn't look anywhere near as simple as for the DB2 driver.

除非将readme.txt打包在JAR中(可能但不太可能),否则前一种方法是唯一可以单独使用JAR文件的方法。编写Java程序并且可能是一个将这种方法应用于任务的包装器脚本应该不会太难,但它看起来并不像DB2驱动程序那么简单。