Found the root of the problem. Looks like the SmartClient handling of TINYINT will only work with the JDBC setting tinyInt1isBit=false, but the default is tinyInt1isBit=true. I guess now I need to figure out how to set tinyInt1isBit=false in server.properties. (But it seems like the default /should/ work. :-)
From http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-type-conversions.html
TINIYINT: "java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not."
===== test ==================
===== output ==================
From http://dev.mysql.com/doc/refman/5.5/en/connector-j-reference-type-conversions.html
TINIYINT: "java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not."
===== test ==================
Code:
import java.sql.*; public class TinyintJdbcTest { public static void main(String[] args) throws Exception { // Mysql JDBC defaults to tinyInt1isBit=true doIt(true); // But SmartClient code would only work if tinyInt1isBit=false doIt(false); } private static void doIt(boolean tinyInt1isBit) { System.out.println("\n--- testing with tinyInt1isBit = " + tinyInt1isBit + "------------------"); try { Class.forName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource"); Connection connect = DriverManager .getConnection("jdbc:mysql://localhost/myapp?user=myapp&password=changeme" + "&tinyInt1isBit=" + tinyInt1isBit); Statement statement = connect.createStatement(); ResultSet resultSet = statement.executeQuery("SELECT id, enabled FROM SomeRule"); writeResultSet(resultSet); } catch (Exception e) { } } private static void writeResultSet(ResultSet resultSet) throws SQLException { while (resultSet.next()) { String id = resultSet.getString("id"); String enabled = resultSet.getString("enabled"); Object obj = resultSet.getObject("enabled"); String objType = obj.getClass().getName(); Object result = "1".equals(obj.toString()) ? Boolean.TRUE : Boolean.FALSE; System.out.println("ID=" + id + ", enabled=" + enabled + ", objType=" + objType + ", result=" + result); } } }
Code:
--- testing with tinyInt1isBit = true------------------ ID=1, enabled=1, objType=java.lang.Boolean, result=false ID=2, enabled=0, objType=java.lang.Boolean, result=false --- testing with tinyInt1isBit = false------------------ ID=1, enabled=1, objType=java.lang.Integer, result=true ID=2, enabled=0, objType=java.lang.Integer, result=false
Comment