[TD-6809]: Fix jdbc NPE (#6814)
This commit is contained in:
parent
99aca608a5
commit
e811cb0ad8
|
@ -68,6 +68,8 @@ CMakeError.log
|
|||
*.o
|
||||
version.c
|
||||
taos.rc
|
||||
src/connector/jdbc/.classpath
|
||||
src/connector/jdbc/.project
|
||||
src/connector/jdbc/.settings/
|
||||
tests/comparisonTest/cassandra/cassandratest/.classpath
|
||||
tests/comparisonTest/cassandra/cassandratest/.project
|
||||
|
|
|
@ -57,8 +57,8 @@ public class TSDBPreparedStatement extends TSDBStatement implements PreparedStat
|
|||
parameterCnt++;
|
||||
}
|
||||
}
|
||||
parameters = new Object[parameterCnt];
|
||||
}
|
||||
parameters = new Object[parameterCnt];
|
||||
|
||||
if (parameterCnt > 1) {
|
||||
// the table name is also a parameter, so ignore it.
|
||||
|
|
|
@ -22,16 +22,16 @@ public class RestfulPreparedStatement extends RestfulStatement implements Prepar
|
|||
super(conn, database);
|
||||
this.rawSql = sql;
|
||||
|
||||
if (sql.contains("?")) {
|
||||
int parameterCnt = 0;
|
||||
if (sql.contains("?")) {
|
||||
for (int i = 0; i < sql.length(); i++) {
|
||||
if ('?' == sql.charAt(i)) {
|
||||
parameterCnt++;
|
||||
}
|
||||
}
|
||||
parameters = new Object[parameterCnt];
|
||||
this.isPrepared = true;
|
||||
}
|
||||
parameters = new Object[parameterCnt];
|
||||
|
||||
// build parameterMetaData
|
||||
this.parameterMetaData = new RestfulParameterMetaData(parameters);
|
||||
|
|
|
@ -15,6 +15,8 @@ public class RestfulPreparedStatementTest {
|
|||
private static PreparedStatement pstmt_insert;
|
||||
private static final String sql_select = "select * from t1 where ts > ? and ts <= ? and f1 >= ?";
|
||||
private static PreparedStatement pstmt_select;
|
||||
private static final String sql_without_parameters = "select count(*) from t1";
|
||||
private static PreparedStatement pstmt_without_parameters;
|
||||
|
||||
@Test
|
||||
public void executeQuery() throws SQLException {
|
||||
|
@ -237,6 +239,7 @@ public class RestfulPreparedStatementTest {
|
|||
@Test
|
||||
public void clearParameters() throws SQLException {
|
||||
pstmt_insert.clearParameters();
|
||||
pstmt_without_parameters.clearParameters();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -382,6 +385,7 @@ public class RestfulPreparedStatementTest {
|
|||
|
||||
pstmt_insert = conn.prepareStatement(sql_insert);
|
||||
pstmt_select = conn.prepareStatement(sql_select);
|
||||
pstmt_without_parameters = conn.prepareStatement(sql_without_parameters);
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -394,6 +398,8 @@ public class RestfulPreparedStatementTest {
|
|||
pstmt_insert.close();
|
||||
if (pstmt_select != null)
|
||||
pstmt_select.close();
|
||||
if (pstmt_without_parameters != null)
|
||||
pstmt_without_parameters.close();
|
||||
if (conn != null)
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
|
|
Loading…
Reference in New Issue