jdbc connector
This commit is contained in:
parent
351757c7ba
commit
1a60dadd0d
|
|
@ -946,3 +946,34 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_setTableNameTagsI
|
|||
|
||||
return JNI_SUCCESS;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_com_taosdata_jdbc_TSDBJNIConnector_insertLinesImp(JNIEnv *env, jobject jobj,
|
||||
jobjectArray lines, jlong conn) {
|
||||
TAOS *taos = (TAOS *)conn;
|
||||
if (taos == NULL) {
|
||||
jniError("jobj:%p, connection already closed", jobj);
|
||||
return JNI_CONNECTION_NULL;
|
||||
}
|
||||
|
||||
int numLines = (*env)->GetArrayLength(env, lines);
|
||||
char** c_lines = calloc(numLines, sizeof(char*));
|
||||
|
||||
for (int i = 0; i < numLines; ++i) {
|
||||
jstring line = (jstring) ((*env)->GetObjectArrayElement(env, lines, i));
|
||||
c_lines[i] = (char*)(*env)->GetStringUTFChars(env, line, 0);
|
||||
}
|
||||
|
||||
int code = taos_insert_lines(taos, c_lines, numLines);
|
||||
|
||||
for (int i = 0; i < numLines; ++i) {
|
||||
jstring line = (jstring) ((*env)->GetObjectArrayElement(env, lines, i));
|
||||
(*env)->ReleaseStringUTFChars(env, line, c_lines[i]);
|
||||
}
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
jniError("jobj:%p, conn:%p, code:%s", jobj, taos, tstrerror(code));
|
||||
return JNI_TDENGINE_ERROR;
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
@ -348,4 +348,13 @@ public class TSDBJNIConnector {
|
|||
}
|
||||
|
||||
private native int closeStmt(long stmt, long con);
|
||||
|
||||
public void insertLines(String[] lines) {
|
||||
int code = insertLines(lines, this.taos);
|
||||
if (code != TSDBConstants.JNI_SUCCESS) {
|
||||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_UNKNOWN, "failed to insertLines");
|
||||
}
|
||||
}
|
||||
|
||||
private native int insertLinesImp(String[] lines, long conn);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,10 @@ public class TSDBJNIConnectorTest {
|
|||
throw TSDBError.createSQLException(TSDBErrorNumbers.ERROR_JNI_RESULT_SET_NULL);
|
||||
}
|
||||
// close statement
|
||||
connector.executeQuery("use d");
|
||||
String[] lines = new String[] {"st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns",
|
||||
"st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns"};
|
||||
connector.insetLines(lines);
|
||||
|
||||
// close connection
|
||||
connector.closeConnection();
|
||||
|
|
|
|||
Loading…
Reference in New Issue