@Override public Object getObject(int columnIndex)throws SQLException { checkRowPos(); checkColumnBounds(columnIndex);
int columnIndexMinusOne = columnIndex - 1;
// we can't completely rely on code below because primitives have default values for null (e.g. int->0) if (this.thisRow.getNull(columnIndexMinusOne)) { returnnull; }
Field field = this.columnDefinition.getFields()[columnIndexMinusOne]; switch (field.getMysqlType()) { case BIT: // TODO Field sets binary and blob flags if the length of BIT field is > 1; is it needed at all? if (field.isBinary() || field.isBlob()) { byte[] data = getBytes(columnIndex);
if (this.connection.getPropertySet().getBooleanProperty(PropertyKey.autoDeserialize).getValue()) { Object obj = data;
case BOOLEAN: return Boolean.valueOf(getBoolean(columnIndex));
case TINYINT: return Integer.valueOf(getByte(columnIndex));
case TINYINT_UNSIGNED: case SMALLINT: case SMALLINT_UNSIGNED: case MEDIUMINT: case MEDIUMINT_UNSIGNED: case INT: return Integer.valueOf(getInt(columnIndex));
case INT_UNSIGNED: case BIGINT: return Long.valueOf(getLong(columnIndex));
case BIGINT_UNSIGNED: return getBigInteger(columnIndex);
case DECIMAL: case DECIMAL_UNSIGNED: String stringVal = getString(columnIndex);
if (stringVal != null) { if (stringVal.length() == 0) { returnnew BigDecimal(0); }
case FLOAT: case FLOAT_UNSIGNED: returnnew Float(getFloat(columnIndex));
case DOUBLE: case DOUBLE_UNSIGNED: returnnew Double(getDouble(columnIndex));
case CHAR: case ENUM: case SET: case VARCHAR: case TINYTEXT: return getString(columnIndex);
case TEXT: case MEDIUMTEXT: case LONGTEXT: case JSON: return getStringForClob(columnIndex);
case GEOMETRY: return getBytes(columnIndex);
case BINARY: case VARBINARY: case TINYBLOB: case MEDIUMBLOB: case LONGBLOB: case BLOB: if (field.isBinary() || field.isBlob()) { byte[] data = getBytes(columnIndex);
if (this.connection.getPropertySet().getBooleanProperty(PropertyKey.autoDeserialize).getValue()) { Object obj = data;
try (Connection conn = DriverManager.getConnection(url, user, password); PreparedStatement ps = conn.prepareStatement(sql); ResultSet rs = ps.executeQuery()) { while (rs.next()) { ResultSetMetaData rsmd = rs.getMetaData(); int columnCount = rsmd.getColumnCount(); for (int i = 1; i <= columnCount; i++) { String columnTypeName = rsmd.getColumnTypeName(i); String column = JdbcUtils.lookupColumnName(rsmd, i);
// 自定义类型转换 int columnType = rsmd.getColumnType(i); Object value = null; switch (columnType) { case Types.CHAR: case Types.NCHAR: case Types.VARCHAR: case Types.LONGVARCHAR: case Types.NVARCHAR: case Types.LONGNVARCHAR: value = rs.getString(i); break; case Types.SMALLINT: case Types.TINYINT: case Types.INTEGER: case Types.BIGINT: value = rs.getLong(i); break; case Types.NUMERIC: case Types.DECIMAL: value = rs.getDouble(i); break; case Types.DATE: case Types.TIMESTAMP: value = rs.getDate(i); break; default: System.out.println("columnType:" + columnType); thrownew RuntimeException("不支持的参数类型"); }