diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java index ee446a2986f32078f6c4dc454d067403674cab86..6518bf10e444a05073206e1ef72b8f21a87e26b1 100644 --- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java +++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBResultSetRowData.java @@ -26,7 +26,7 @@ public class TSDBResultSetRowData { public TSDBResultSetRowData(int colSize) { this.setColSize(colSize); } - + public TSDBResultSetRowData() { this.data = new ArrayList<>(); this.setColSize(0); @@ -53,7 +53,7 @@ public class TSDBResultSetRowData { public boolean getBoolean(int col, int srcType) throws SQLException { Object obj = data.get(col); - + switch(srcType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return (Boolean) obj; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj) == 1.0? Boolean.TRUE:Boolean.FALSE; @@ -64,10 +64,10 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj) == 1L? Boolean.TRUE:Boolean.FALSE; } - + return Boolean.TRUE; } - + public void setByte(int col, byte value) { data.set(col, value); } @@ -82,20 +82,20 @@ public class TSDBResultSetRowData { public int getInt(int col, int srcType) throws SQLException { Object obj = data.get(col); - + switch(srcType) { - case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; - case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue(); - case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double)obj).intValue(); - case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; - case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj; - case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; - case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: - case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj).intValue(); - case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj); + case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; + case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_DOUBLE: return ((Double)obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_TINYINT: return (Byte) obj; + case TSDBConstants.TSDB_DATA_TYPE_SMALLINT:return (Short) obj; + case TSDBConstants.TSDB_DATA_TYPE_INT: return (Integer) obj; + case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: + case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return ((Long) obj).intValue(); + case TSDBConstants.TSDB_DATA_TYPE_NCHAR: + case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Integer.parseInt((String) obj); } - + return 0; } @@ -105,7 +105,7 @@ public class TSDBResultSetRowData { public long getLong(int col, int srcType) throws SQLException { Object obj = data.get(col); - + switch(srcType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return ((Float) obj).longValue(); @@ -116,9 +116,9 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; case TSDBConstants.TSDB_DATA_TYPE_NCHAR: - case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj); + case TSDBConstants.TSDB_DATA_TYPE_BINARY: return Long.parseLong((String) obj); } - + return 0; } @@ -128,7 +128,7 @@ public class TSDBResultSetRowData { public float getFloat(int col, int srcType) throws SQLException { Object obj = data.get(col); - + switch(srcType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj; @@ -139,7 +139,7 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; } - + return 0; } @@ -149,7 +149,7 @@ public class TSDBResultSetRowData { public double getDouble(int col, int srcType) throws SQLException { Object obj = data.get(col); - + switch(srcType) { case TSDBConstants.TSDB_DATA_TYPE_BOOL: return Boolean.TRUE.equals(obj)? 1:0; case TSDBConstants.TSDB_DATA_TYPE_FLOAT: return (Float) obj; @@ -160,7 +160,7 @@ public class TSDBResultSetRowData { case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP: case TSDBConstants.TSDB_DATA_TYPE_BIGINT: return (Long) obj; } - + return 0; } @@ -180,7 +180,7 @@ public class TSDBResultSetRowData { * The original type may not be a string type, but will be converted to by calling this method * @param col column index * @return - * @throws SQLException + * @throws SQLException */ public String getString(int col, int srcType) throws SQLException { if (srcType == TSDBConstants.TSDB_DATA_TYPE_BINARY || srcType == TSDBConstants.TSDB_DATA_TYPE_NCHAR) { diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java index 83ef6241588099b05a33919abba4abd7e7fee8ed..75e1876536a0606a57c66ca2137f9a1161dce98a 100644 --- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java +++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/TSDBDatabaseMetaDataTest.java @@ -642,9 +642,13 @@ public class TSDBDatabaseMetaDataTest { ResultSet tables = metaData.getTables("log", "", null, null); ResultSetMetaData metaData = tables.getMetaData(); while (tables.next()) { - System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t"); - System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t"); - System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n"); +// System.out.print(metaData.getColumnLabel(3) + ":" + tables.getString(3) + "\t"); +// System.out.print(metaData.getColumnLabel(4) + ":" + tables.getString(4) + "\t"); +// System.out.print(metaData.getColumnLabel(5) + ":" + tables.getString(5) + "\n"); + for (int i = 1; i <= metaData.getColumnCount(); i++) { + System.out.print(metaData.getColumnLabel(i) + ": " + tables.getString(i) + "\t"); + } + System.out.println(); } System.out.println(); Assert.assertNotNull(tables);