我想使用 Java 对 MySQL 数据库执行查询。代码如下所示:
ResultSet resultSet = statement.executeQuery("select col1 from tb1 inner join tb2 on tb1.col2 = tb2.col3 where col4='"+foo+"'");
当我使用 shell 时,该查询工作正常,但当我使用 Java 运行它时,该查询不起作用,因为它说 col4 不存在。但 col4 存在。
我刚刚尝试过这样的事情;
select col1 from dbname.tb1 as a inner join dbname.tb2 as b on a.col2 = b.col3 where b.col4 = 'foo'
最佳答案
您应该使用表前缀“tb1”或“tb2”来调用 col4。
例如: 从 tb1 中选择 tb1.col1 在 tb1.col2 = tb2.col3 上内连接 tb2,其中 tb1.col4=...
关于java - 即使该列存在,我也会收到未找到列的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50511672/