diff --git a/cmake/install.inc b/cmake/install.inc
index 01d3c8a4df234432235e1e0dfea64662dd6f481e..5823ef743ed5b5b57f3915a82aa9e1e21f850d2f 100755
--- a/cmake/install.inc
+++ b/cmake/install.inc
@@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS)
#INSTALL(TARGETS taos RUNTIME DESTINATION driver)
#INSTALL(TARGETS shell RUNTIME DESTINATION .)
IF (TD_MVN_INSTALLED)
- INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.24-dist.jar DESTINATION connector/jdbc)
+ INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.25-dist.jar DESTINATION connector/jdbc)
ENDIF ()
ELSEIF (TD_DARWIN)
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt
index 540dc8eb589ccab79591377a7863f8643f0fb981..eb158b1f769f97482a314f2797ec247f756b3b39 100644
--- a/src/connector/jdbc/CMakeLists.txt
+++ b/src/connector/jdbc/CMakeLists.txt
@@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED)
ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME}
POST_BUILD
COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
- COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.24-dist.jar ${LIBRARY_OUTPUT_PATH}
+ COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.25-dist.jar ${LIBRARY_OUTPUT_PATH}
COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml
COMMENT "build jdbc driver")
ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME})
diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml
index 935b3f7e4aeb3ae3d4ba87d256fbb7484bb549fe..eb8c92575c4b9953e5b8155d2bf2b1ded4772a26 100755
--- a/src/connector/jdbc/deploy-pom.xml
+++ b/src/connector/jdbc/deploy-pom.xml
@@ -5,7 +5,7 @@
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.24
+ 2.0.25
jar
JDBCDriver
diff --git a/src/connector/jdbc/pom.xml b/src/connector/jdbc/pom.xml
index 5d7c89e2d2d9e69adcbcc89cdb5ec056b9197719..1f75754b0c46ec0afced88743c5aba1d308c24ec 100755
--- a/src/connector/jdbc/pom.xml
+++ b/src/connector/jdbc/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.taosdata.jdbc
taos-jdbcdriver
- 2.0.24
+ 2.0.25
jar
JDBCDriver
https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc
@@ -62,6 +62,14 @@
+
+
+ src/main/resources
+
+ **/*.md
+
+
+
org.apache.maven.plugins
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
index 999df06fc75b5d77ade53c9842a80de41ac610a5..7df7252ae2010b5aa5e8f74de2cca55844e25b83 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/AbstractParameterMetaData.java
@@ -15,7 +15,7 @@ public abstract class AbstractParameterMetaData extends WrapperImpl implements P
@Override
public int getParameterCount() throws SQLException {
- return parameters.length;
+ return parameters == null ? 0 : parameters.length;
}
@Override
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
index 7d3741917cb9166a5b29e69ad2b4d3f5023bd43d..5e3ffffa4fe7326b8c1e89ac91a37e95c346784f 100755
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBJNIConnector.java
@@ -29,45 +29,25 @@ public class TSDBJNIConnector {
private static volatile Boolean isInitialized = false;
private TaosInfo taosInfo = TaosInfo.getInstance();
+ // Connection pointer used in C
+ private long taos = TSDBConstants.JNI_NULL_POINTER;
+ // result set status in current connection
+ private boolean isResultsetClosed = true;
+ private int affectedRows = -1;
static {
System.loadLibrary("taos");
System.out.println("java.library.path:" + System.getProperty("java.library.path"));
}
- /**
- * Connection pointer used in C
- */
- private long taos = TSDBConstants.JNI_NULL_POINTER;
-
- /**
- * Result set pointer for the current connection
- */
-// private long taosResultSetPointer = TSDBConstants.JNI_NULL_POINTER;
-
- /**
- * result set status in current connection
- */
- private boolean isResultsetClosed = true;
- private int affectedRows = -1;
-
- /**
- * Whether the connection is closed
- */
public boolean isClosed() {
return this.taos == TSDBConstants.JNI_NULL_POINTER;
}
- /**
- * Returns the status of last result set in current connection
- */
public boolean isResultsetClosed() {
return this.isResultsetClosed;
}
- /**
- * Initialize static variables in JNI to optimize performance
- */
public static void init(String configDir, String locale, String charset, String timezone) throws SQLWarning {
synchronized (isInitialized) {
if (!isInitialized) {
@@ -93,11 +73,6 @@ public class TSDBJNIConnector {
public static native String getTsCharset();
- /**
- * Get connection pointer
- *
- * @throws SQLException
- */
public boolean connect(String host, int port, String dbName, String user, String password) throws SQLException {
if (this.taos != TSDBConstants.JNI_NULL_POINTER) {
// this.closeConnectionImp(this.taos);
@@ -185,13 +160,6 @@ public class TSDBJNIConnector {
private native String getErrMsgImp(long pSql);
- /**
- * Get resultset pointer
- * Each connection should have a single open result set at a time
- */
-// public long getResultSet() {
-// return taosResultSetPointer;
-// }
private native long getResultSetImp(long connection, long pSql);
public boolean isUpdateQuery(long pSql) {
@@ -231,6 +199,7 @@ public class TSDBJNIConnector {
// }
// return resCode;
// }
+
private native int freeResultSetImp(long connection, long result);
/**
@@ -323,8 +292,7 @@ public class TSDBJNIConnector {
* Validate if a create table sql statement is correct without actually creating that table
*/
public boolean validateCreateTableSql(String sql) {
- long connection = taos;
- int res = validateCreateTableSqlImp(connection, sql.getBytes());
+ int res = validateCreateTableSqlImp(taos, sql.getBytes());
return res != 0 ? false : true;
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
index 856f5257bffbee1858e431694c5229f4bf462ecd..5c2d4c45b079974672843b232e38fcd9d010b0c4 100644
--- a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/rs/RestfulResultSet.java
@@ -84,9 +84,9 @@ public class RestfulResultSet extends AbstractResultSet implements ResultSet {
case TSDBConstants.TSDB_DATA_TYPE_TIMESTAMP:
return new Timestamp(row.getDate(colIndex).getTime());
case TSDBConstants.TSDB_DATA_TYPE_BINARY:
- return row.getString(colIndex).getBytes();
+ return row.getString(colIndex) == null ? null : row.getString(colIndex).getBytes();
case TSDBConstants.TSDB_DATA_TYPE_NCHAR:
- return row.getString(colIndex);
+ return row.getString(colIndex) == null ? null : row.getString(colIndex);
default:
return row.get(colIndex);
}
diff --git a/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/OSUtils.java b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/OSUtils.java
new file mode 100644
index 0000000000000000000000000000000000000000..a67b4763f99164a58439df25d944cac913ab36d9
--- /dev/null
+++ b/src/connector/jdbc/src/main/java/com/taosdata/jdbc/utils/OSUtils.java
@@ -0,0 +1,17 @@
+package com.taosdata.jdbc.utils;
+
+public class OSUtils {
+ private static final String OS = System.getProperty("os.name").toLowerCase();
+
+ public static boolean isWindows() {
+ return OS.indexOf("win") >= 0;
+ }
+
+ public static boolean isMac() {
+ return OS.indexOf("mac") >= 0;
+ }
+
+ public static boolean isLinux() {
+ return OS.indexOf("nux") >= 0;
+ }
+}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java
index 580b2ac1b5ed98dfa60e016de4b40e106b56fa61..9826e6ed764f8319c70a8a2c1edf7b2444b4f21d 100644
--- a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/DriverAutoloadTest.java
@@ -17,7 +17,6 @@ public class DriverAutoloadTest {
@Test
public void testRestful() throws SQLException {
-// Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
Connection conn = DriverManager.getConnection(url, properties);
Assert.assertNotNull(conn);
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcRestfulTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcRestfulTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..f2ac94adc1b6e7d94e52650dcfbb5664c8f39760
--- /dev/null
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/cases/NullValueInResultSetForJdbcRestfulTest.java
@@ -0,0 +1,64 @@
+package com.taosdata.jdbc.cases;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.sql.*;
+
+public class NullValueInResultSetForJdbcRestfulTest {
+
+ private static final String host = "127.0.0.1";
+ Connection conn;
+
+ @Test
+ public void test() {
+ try (Statement stmt = conn.createStatement()) {
+ ResultSet rs = stmt.executeQuery("select * from weather");
+ ResultSetMetaData meta = rs.getMetaData();
+ while (rs.next()) {
+ for (int i = 1; i <= meta.getColumnCount(); i++) {
+ Object value = rs.getObject(i);
+ System.out.print(meta.getColumnLabel(i) + ": " + value + "\t");
+ }
+ System.out.println();
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Before
+ public void before() throws SQLException {
+ final String url = "jdbc:TAOS-RS://" + host + ":6041/?user=root&password=taosdata";
+ conn = DriverManager.getConnection(url);
+ try (Statement stmt = conn.createStatement()) {
+ stmt.execute("drop database if exists test_null");
+ stmt.execute("create database if not exists test_null");
+ stmt.execute("use test_null");
+ stmt.execute("create table weather(ts timestamp, f1 int, f2 bigint, f3 float, f4 double, f5 smallint, f6 tinyint, f7 bool, f8 binary(64), f9 nchar(64))");
+ stmt.executeUpdate("insert into weather(ts, f1) values(now+1s, 1)");
+ stmt.executeUpdate("insert into weather(ts, f2) values(now+2s, 2)");
+ stmt.executeUpdate("insert into weather(ts, f3) values(now+3s, 3.0)");
+ stmt.executeUpdate("insert into weather(ts, f4) values(now+4s, 4.0)");
+ stmt.executeUpdate("insert into weather(ts, f5) values(now+5s, 5)");
+ stmt.executeUpdate("insert into weather(ts, f6) values(now+6s, 6)");
+ stmt.executeUpdate("insert into weather(ts, f7) values(now+7s, true)");
+ stmt.executeUpdate("insert into weather(ts, f8) values(now+8s, 'hello')");
+ stmt.executeUpdate("insert into weather(ts, f9) values(now+9s, '涛思数据')");
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @After
+ public void after() {
+ try {
+ if (conn != null)
+ conn.close();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/OSUtilsTest.java b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/OSUtilsTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..fd6c83ad1cacfb351bcc1d35a5cf777213ad876d
--- /dev/null
+++ b/src/connector/jdbc/src/test/java/com/taosdata/jdbc/utils/OSUtilsTest.java
@@ -0,0 +1,30 @@
+package com.taosdata.jdbc.utils;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class OSUtilsTest {
+
+ private String OS;
+
+ @Test
+ public void inWindows() {
+ Assert.assertEquals(OS.indexOf("win") >= 0, OSUtils.isWindows());
+ }
+
+ @Test
+ public void isMac() {
+ Assert.assertEquals(OS.indexOf("mac") >= 0, OSUtils.isMac());
+ }
+
+ @Test
+ public void isLinux() {
+ Assert.assertEquals(OS.indexOf("nux") >= 0, OSUtils.isLinux());
+ }
+
+ @Before
+ public void before() {
+ OS = System.getProperty("os.name").toLowerCase();
+ }
+}
\ No newline at end of file