commit
9167cf932a
|
@ -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.16-dist.jar DESTINATION connector/jdbc)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.17-dist.jar DESTINATION connector/jdbc)
|
||||
ENDIF ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh")
|
||||
|
|
|
@ -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.16-dist.jar ${LIBRARY_OUTPUT_PATH}
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.17-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})
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.16</version>
|
||||
<version>2.0.17</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>JDBCDriver</name>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.16</version>
|
||||
<version>2.0.17</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>JDBCDriver</name>
|
||||
<url>https://github.com/taosdata/TDengine/tree/master/src/connector/jdbc</url>
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.sql.SQLException;
|
|||
*/
|
||||
public class CatalogResultSet extends TSDBResultSetWrapper {
|
||||
|
||||
|
||||
public CatalogResultSet(ResultSet resultSet) {
|
||||
super.setOriginalResultSet(resultSet);
|
||||
}
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/*
|
||||
* TDengine only supports a subset of the standard SQL, thus this implemetation of the
|
||||
* standard JDBC API contains more or less some adjustments customized for certain
|
||||
* compatibility needs.
|
||||
*/
|
||||
public class GetColumnsResultSet extends TSDBResultSetWrapper {
|
||||
private String catalog;
|
||||
private String schemaPattern;
|
||||
private String tableNamePattern;
|
||||
private String columnNamePattern;
|
||||
|
||||
public GetColumnsResultSet(ResultSet resultSet, String catalog, String schemaPattern, String tableNamePattern, String columnNamePattern) {
|
||||
super.setOriginalResultSet(resultSet);
|
||||
this.catalog = catalog;
|
||||
this.schemaPattern = schemaPattern;
|
||||
this.tableNamePattern = tableNamePattern;
|
||||
this.columnNamePattern = columnNamePattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case 1:
|
||||
return catalog;
|
||||
case 2:
|
||||
return null;
|
||||
case 3:
|
||||
return tableNamePattern;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -620,6 +620,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
|
|||
ResultSet tables = stmt.executeQuery("show tables");
|
||||
while (tables.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
|
||||
rowData.setString(0, dbname);
|
||||
rowData.setString(2, tables.getString("table_name"));
|
||||
rowData.setString(3, "TABLE");
|
||||
rowData.setString(4, "");
|
||||
|
@ -629,6 +630,7 @@ public class TSDBDatabaseMetaData implements java.sql.DatabaseMetaData {
|
|||
ResultSet stables = stmt.executeQuery("show stables");
|
||||
while (stables.next()) {
|
||||
TSDBResultSetRowData rowData = new TSDBResultSetRowData(10);
|
||||
rowData.setString(0, dbname);
|
||||
rowData.setString(2, stables.getString("name"));
|
||||
rowData.setString(3, "TABLE");
|
||||
rowData.setString(4, "STABLE");
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
import java.sql.ParameterMetaData;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TSDBParameterMetaData implements ParameterMetaData {
|
||||
@Override
|
||||
public int getParameterCount() throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isNullable(int param) throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSigned(int param) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPrecision(int param) throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getScale(int param) throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParameterType(int param) throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameterTypeName(int param) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParameterClassName(int param) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getParameterMode(int param) throws SQLException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*****************************************************************************/
|
||||
package com.taosdata.jdbc;
|
||||
|
||||
public interface TSDBSubscribeCallBack {
|
||||
void invoke(TSDBResultSet resultSet);
|
||||
}
|
|
@ -44,6 +44,8 @@ public class RestfulDriver extends AbstractTaosDriver {
|
|||
String result = HttpClientPoolUtil.execute(loginUrl);
|
||||
JSONObject jsonResult = JSON.parseObject(result);
|
||||
String status = jsonResult.getString("status");
|
||||
String token = jsonResult.getString("desc");
|
||||
HttpClientPoolUtil.token = token;
|
||||
if (!status.equals("succ")) {
|
||||
throw new SQLException(jsonResult.getString("desc"));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.nio.charset.Charset;
|
|||
public class HttpClientPoolUtil {
|
||||
public static PoolingHttpClientConnectionManager cm = null;
|
||||
public static CloseableHttpClient httpClient = null;
|
||||
public static String token = "cm9vdDp0YW9zZGF0YQ==";
|
||||
/**
|
||||
* 默认content 类型
|
||||
*/
|
||||
|
@ -61,9 +62,7 @@ public class HttpClientPoolUtil {
|
|||
try {
|
||||
return Long.parseLong(value) * 1000;
|
||||
} catch (Exception e) {
|
||||
new Exception(
|
||||
"format KeepAlive timeout exception, exception:" + e.toString())
|
||||
.printStackTrace();
|
||||
new Exception("format KeepAlive timeout exception, exception:" + e.toString()).printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -96,7 +95,7 @@ public class HttpClientPoolUtil {
|
|||
initPools();
|
||||
}
|
||||
method = (HttpEntityEnclosingRequestBase) getRequest(uri, HttpPost.METHOD_NAME, DEFAULT_CONTENT_TYPE, 0);
|
||||
method.setHeader("Authorization", "Basic cm9vdDp0YW9zZGF0YQ==");
|
||||
method.setHeader("Authorization", "Taosd " + token);
|
||||
method.setHeader("Content-Type", "text/plain");
|
||||
method.setEntity(new StringEntity(data, Charset.forName("UTF-8")));
|
||||
HttpContext context = HttpClientContext.create();
|
||||
|
|
|
@ -642,6 +642,7 @@ public class TSDBDatabaseMetaDataTest {
|
|||
ResultSet tables = metaData.getTables("log", "", null, null);
|
||||
ResultSetMetaData metaData = tables.getMetaData();
|
||||
while (tables.next()) {
|
||||
System.out.print(metaData.getColumnLabel(1) + ":" + tables.getString(1) + "\t");
|
||||
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");
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class AuthenticationTest {
|
||||
|
||||
// private static final String host = "127.0.0.1";
|
||||
private static final String host = "master";
|
||||
private static final String user = "root";
|
||||
private static final String password = "123456";
|
||||
private Connection conn;
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
// change password
|
||||
try {
|
||||
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=taosdata");
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("alter user " + user + " pass '" + password + "'");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// use new to login and execute query
|
||||
try {
|
||||
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("show databases");
|
||||
ResultSet rs = stmt.getResultSet();
|
||||
ResultSetMetaData meta = rs.getMetaData();
|
||||
while (rs.next()) {
|
||||
for (int i = 1; i <= meta.getColumnCount(); i++) {
|
||||
System.out.print(meta.getColumnLabel(i) + ":" + rs.getString(i) + "\t");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// change password back
|
||||
try {
|
||||
conn = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=" + user + "&password=" + password);
|
||||
Statement stmt = conn.createStatement();
|
||||
stmt.execute("alter user " + user + " pass 'taosdata'");
|
||||
stmt.close();
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
try {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -6,6 +6,7 @@ import org.junit.Test;
|
|||
import java.sql.*;
|
||||
|
||||
public class RestfulDriverTest {
|
||||
private static final String host = "master";
|
||||
|
||||
@Test
|
||||
public void connect() {
|
||||
|
@ -15,9 +16,9 @@ public class RestfulDriverTest {
|
|||
@Test
|
||||
public void acceptsURL() throws SQLException {
|
||||
Driver driver = new RestfulDriver();
|
||||
boolean isAccept = driver.acceptsURL("jdbc:TAOS-RS://master:6041");
|
||||
boolean isAccept = driver.acceptsURL("jdbc:TAOS-RS://" + host + ":6041");
|
||||
Assert.assertTrue(isAccept);
|
||||
isAccept = driver.acceptsURL("jdbc:TAOS://master:6041");
|
||||
isAccept = driver.acceptsURL("jdbc:TAOS://" + host + ":6041");
|
||||
Assert.assertFalse(isAccept);
|
||||
}
|
||||
|
||||
|
@ -26,6 +27,9 @@ public class RestfulDriverTest {
|
|||
Driver driver = new RestfulDriver();
|
||||
final String url = "";
|
||||
DriverPropertyInfo[] propertyInfo = driver.getPropertyInfo(url, null);
|
||||
for (DriverPropertyInfo prop : propertyInfo) {
|
||||
System.out.println(prop);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.taosdata.jdbc.rs;
|
||||
|
||||
|
||||
import org.junit.*;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
|
@ -10,12 +9,13 @@ import java.util.Random;
|
|||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class RestfulJDBCTest {
|
||||
|
||||
private static final String host = "master";
|
||||
private Connection connection;
|
||||
|
||||
@Before
|
||||
public void before() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://master:6041/restful_test?user=root&password=taosdata");
|
||||
connection = DriverManager.getConnection("jdbc:TAOS-RS://" + host + ":6041/restful_test?user=root&password=taosdata");
|
||||
}
|
||||
|
||||
@After
|
||||
|
|
|
@ -21,4 +21,5 @@ public class SqlSyntaxValidatorTest {
|
|||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database test"));
|
||||
Assert.assertTrue(SqlSyntaxValidator.isUseSql("drop database if exist test"));
|
||||
}
|
||||
|
||||
}
|
|
@ -67,9 +67,9 @@
|
|||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>2.0.16</version>
|
||||
<!-- <scope>system</scope>-->
|
||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
||||
<version>2.0.17</version>
|
||||
<!-- <scope>system</scope>-->
|
||||
<!-- <systemPath>${project.basedir}/src/main/resources/lib/taos-jdbcdriver-2.0.15-dist.jar</systemPath>-->
|
||||
</dependency>
|
||||
<!-- fastjson -->
|
||||
<dependency>
|
||||
|
|
Loading…
Reference in New Issue