Description:
Hello everyone.I operate column that the type is tinyint(1) by mysql-connection-J 8.0.26 or mysql-connection-j 5.6. The result is different to update the connection url.The version is 5.6 add "tinyInt1isBit=false" int the url,the result is int,but use 8.0 still is boolean.
so if i want to return int data rather than boolean in the version is 8.0 by update the connection url,like the version is 5.6's result.what should I do?
How to repeat:
/**
* table A1 DDL statement :
* CREATE TABLE `A1` (
`id` int DEFAULT NULL,
`type` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='ad';
*/
public void testSQL() throws Exception {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("connection database...");
DriverManager.setLoginTimeout(90);
Properties properties = new Properties();
properties.put("remarksReporting", "true");
properties.put("user", "root");
properties.put("password", "aaa");
conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true", "root","Hello123$");
stmt = conn.createStatement();
String sql;
changeDatabase(conn);
sql = "SELECT * FROM `TEST`.`A1`";
ResultSet rs = stmt.executeQuery(sql);
while (rs.next()) {
System.out.println(rs.getObject("type"));
// the result is boolean rather than int
System.out.println(rs.getInt("type")); // it is ok
}
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
se.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (stmt != null) stmt.close();
} catch (SQLException se2) {
}
try {
if (conn != null) conn.close();
} catch (SQLException se) {
se.printStackTrace();
}
}
System.out.println("Goodbye!");
}