未验证 提交 9b1aa21d 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #2952 from taosdata/hotfix/fix_java_connector

fixbug java connector
...@@ -97,7 +97,7 @@ public class TSDBJNIConnector { ...@@ -97,7 +97,7 @@ public class TSDBJNIConnector {
this.taos = this.connectImp(host, port, dbName, user, password); this.taos = this.connectImp(host, port, dbName, user, password);
if (this.taos == TSDBConstants.JNI_NULL_POINTER) { if (this.taos == TSDBConstants.JNI_NULL_POINTER) {
throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(null)), "", this.getErrCode(null)); throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(0L)), "", this.getErrCode(0l));
} }
return true; return true;
...@@ -115,7 +115,7 @@ public class TSDBJNIConnector { ...@@ -115,7 +115,7 @@ public class TSDBJNIConnector {
freeResultSet(taosResultSetPointer); freeResultSet(taosResultSetPointer);
} }
long pSql = 0l; Long pSql = 0l;
try { try {
pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos); pSql = this.executeQueryImp(sql.getBytes(TaosGlobalConfig.getCharset()), this.taos);
} catch (Exception e) { } catch (Exception e) {
...@@ -124,16 +124,11 @@ public class TSDBJNIConnector { ...@@ -124,16 +124,11 @@ public class TSDBJNIConnector {
throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding")); throw new SQLException(TSDBConstants.WrapErrMsg("Unsupported encoding"));
} }
int code = this.getErrCode(pSql); int code = this.getErrCode(pSql);
if (code != 0) {
if (code < 0) {
affectedRows = -1; affectedRows = -1;
if (code == TSDBConstants.JNI_TDENGINE_ERROR) { String err_msg = this.getErrMsg(pSql);
this.freeResultSet(pSql); this.freeResultSet(pSql);
throw new SQLException(TSDBConstants.WrapErrMsg(this.getErrMsg(pSql)), "", this.getErrCode(pSql)); throw new SQLException(TSDBConstants.WrapErrMsg(err_msg), "", code);
} else {
this.freeResultSet(pSql);
throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode(pSql));
}
} }
// Try retrieving result set for the executed SQL using the current connection pointer. If the executed // Try retrieving result set for the executed SQL using the current connection pointer. If the executed
...@@ -151,20 +146,20 @@ public class TSDBJNIConnector { ...@@ -151,20 +146,20 @@ public class TSDBJNIConnector {
/** /**
* Get recent error code by connection * Get recent error code by connection
*/ */
public int getErrCode(Long pSql) { public int getErrCode(long pSql) {
return Math.abs(this.getErrCodeImp(this.taos, pSql)); return this.getErrCodeImp(this.taos, pSql);
} }
private native int getErrCodeImp(long connection, Long pSql); private native int getErrCodeImp(long connection, long pSql);
/** /**
* Get recent error message by connection * Get recent error message by connection
*/ */
public String getErrMsg(Long pSql) { public String getErrMsg(long pSql) {
return this.getErrMsgImp(this.taos, pSql); return this.getErrMsgImp(pSql);
} }
private native String getErrMsgImp(long connection, Long pSql); private native String getErrMsgImp(long pSql);
/** /**
* Get resultset pointer * Get resultset pointer
...@@ -248,7 +243,7 @@ public class TSDBJNIConnector { ...@@ -248,7 +243,7 @@ public class TSDBJNIConnector {
public void closeConnection() throws SQLException { public void closeConnection() throws SQLException {
int code = this.closeConnectionImp(this.taos); int code = this.closeConnectionImp(this.taos);
if (code < 0) { if (code < 0) {
throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode(null)); throw new SQLException(TSDBConstants.FixErrMsg(code), "", this.getErrCode(0l));
} else if (code == 0) { } else if (code == 0) {
this.taos = TSDBConstants.JNI_NULL_POINTER; this.taos = TSDBConstants.JNI_NULL_POINTER;
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册