简体   繁体   English

JDBC SQL Server联接不返回任何结果

[英]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.

相关问题 Java/SQL Server 中的预处理语句不返回任何结果 - Prepared Statement in Java/SQL Server not returning any results 在 SQL Server 中,JDBC getUpdateCount 返回 0,但更新了 1 行 - JDBC getUpdateCount is returning 0, but 1 row is updated, in SQL Server MySQL JDBC返回0结果 - MySQL JDBC returning 0 results 对于 SQL 服务器数据库获取“com.microsoft.sqlserver.jdbc.SQLServerException:必须执行该语句才能获得任何结果。” - For SQL Server database getting “com.microsoft.sqlserver.jdbc.SQLServerException:The statement must be executed before any results can be obtained.” 有没有办法用SQL Server JDBC驱动程序显示PRINT结果? - Is there a way to display PRINT results with SQL server JDBC driver? 相同的查询在 SQL 服务器客户端和 JDBC 客户端中提供不同的结果 - Same query provides different results in SQL Server client and JDBC client SQL Server 2012存储过程在JDBC中不返回任何结果 - SQL Server 2012 stored procedure does not return any result in JDBC jdbc-SQL Server在控制台中未显示任何输出/错误 - jdbc - sql server not showing any output / error in the console 为什么我的 SQL Month 查询没有返回任何结果? - Why is my SQL Month query not returning any results? LDAP不返回任何结果 - LDAP not returning any results
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM