[英]JDBC SQL Server join not returning any results
I'm converting an application that runs currently under MYSQL to use SQL Server. 我正在将当前在MYSQL下运行的应用程序转换为使用SQL Server。 The upshot is, that I have an odd situation! 结果是,我有一个奇怪的情况! The existing query works in MySQL via JDBC, and works inside MySQL as a command line query -- yet, the same query is not working via the SQL Server JDBC driver, despite working inside the SQL Server studio from the command line as a query. 现有查询通过JDBC在MySQL中工作,并且在MySQL内部作为命令行查询工作-尽管通过命令行在SQL Server Studio中作为查询工作,但该查询无法通过SQL Server JDBC驱动程序工作。
Under MYSQL JDBC I get a set of results, under SQL Server JDBC I get 0 results. 在MYSQL JDBC下,我得到了一组结果,在SQL Server JDBC下,我得到了0个结果。
I've tried the query this way (which works in SQL Server from the command line) 我已经尝试过这种查询方式(可从命令行在SQL Server中使用)
SELECT DISTINCT
x,
y
FROM
table1,
table2
WHERE
x = y
AND start_date <= '2015-05-15'
AND end_date >= '2015-05-15'
AND direction LIKE 'Direction';
which inside JDBC looks like this: JDBC内部的内容如下所示:
"select DISTINCT x, y from table1, table2" +
"WHERE x=y and start_date <= ? and end_date >= ? and direction like ?"
The answer was that SQL Server needed the 'like' delimiting by % %. 答案是,SQL Server需要用“%”分隔。 As in this example: 如本例所示:
Using "like" wildcard in prepared statement 在准备好的语句中使用“喜欢”通配符
Our code worked fine with MySQL driver, but the drivers are obviously different in this respect. 我们的代码可以与MySQL驱动程序一起很好地工作,但是驱动程序在这方面显然有所不同。 I've simplified the post in case anyone else gets this problem, and finds this post. 我已经简化了帖子,以防其他人遇到此问题,并找到了该帖子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.