提醒。所以这就是我到目前为止所得到的。我找到了一篇关于如何通过 Java 运行可执行文件的帖子。我使用了它并且 tablediff 实用程序正在运行。但我必须按照 SQL Server 的要求将参数传递给 tablediff 实用程序。
代码:
public static void main(String[] args) throws IOException
{
String sourceserver = "-sourceserver source_name";
String sourcedatabase ="-sourcedatabase dbtest01";
String sourcetable = "-sourcetable article";
String destinationserver = "-destinationserver destination_name";
String destinationdatabase ="-destinationdatabase dbtest02";
String destinationtable = "-destinationtable article";
Process process = new ProcessBuilder("C:\\Program Files\\Microsoft SQL Server\\110\\COM\\tablediff.exe",sourceserver,sourcedatabase,sourcetable,destinationserver,destinationdatabase,destinationtable).start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
System.out.printf("Output of running %s is:", Arrays.toString(args));
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
}
我不断收到此错误:
Output of running [] is:
Microsoft (R) SQL Server Replication Diff Tool
Copyright (c) 2008 Microsoft Corporation
User-specified agent parameter values:
-sourceserver source_name
The parameter '-sourceserver source_name' is invalid.
命令提示符像这样执行它:
C:\Program Files\Microsoft SQL Server\110\COM\>tablediff.exe -sourceserver source_name -sourcedatabase dbtest01 -sourcetab
le article -destinationserver destination_name -destinationdatabase dbtest02 -destin
ationtable article
Microsoft (R) SQL Server Replication Diff Tool
Copyright (c) 2008 Microsoft Corporation
User-specified agent parameter values:
-sourceserver source_name
-sourcedatabase dbtest01
-sourcetable article
-destinationserver destination_name
-destinationdatabase dbtest02
-destinationtable article
Table [dbtest01].[dbo].[article] on source_name and Table [dbtest02].[dbo].[art
icle] on destination_name have 1 differences.
Err id
Dest. Only N'004 '
The requested operation took 9.1819181 seconds.
我不知道为什么程序给出了无效的参数。我尝试将字符串更改为“source_name”等等。不工作。我还尝试将字符串直接传递给 Processbuilder。也不起作用。它给了我同样的错误信息。