package test; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class MySQLBug { private static final String USERNAME = "root"; private static final String PASSWORD = ""; public static void main(String[] args) { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { System.err.println("Could not load MySQL JDBC driver"); System.exit(1); } try { Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test", USERNAME, PASSWORD); test(connection); connection.close(); connection = DriverManager.getConnection("jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=UTF-8", USERNAME, PASSWORD); test(connection); connection.close(); } catch (SQLException e) { e.printStackTrace(); System.exit(2); } } private static void test(Connection connection) throws SQLException { PreparedStatement statement = connection.prepareStatement("SELECT * FROM foo WHERE 'TST123' NOT IN (SELECT baz FROM bam WHERE bam.foo_id = foo.id)"); if (statement.execute()) { ResultSet resultSet = statement.getResultSet(); System.out.println(resultSet.next()); } } }