简体   繁体   中英

Subquery using JDBC?

I have a query in my java program like this -

SELECT * FROM conversation WHERE user_id != 1 AND conversation_id IN 
( SELECT conversation_id FROM conversation WHERE user_id = 1)

This returns 0 rows in the result using jdbc. However if I copy and paste it into phpmyadmin it works fine. So what's going wrong?

I have added ?allowMultiQueries=true to my jdbc connection string to see if that would make a difference but it hasnt.

Edit:

Here is what my table looks like. I am looking to select the ids of users in conversations with user 1. Ive just noticed I left out the ! in the != in the query above, Ive put it in now. So anyone know why this works with phpmyadmin and not jdbc?

在此处输入图片说明

Are you logged in with the identical credentials and to the same database in both JDBC and in phpmyadmin? Been there, done that - was logged into a different (and empty) db and couldn't figure out why the queries were failing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM