Skip to content

Commit

Permalink
Merge branch 'master' into ci/nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
kezhenxu94 committed Oct 7, 2019
2 parents 3531421 + 7d3b285 commit 4e80d8a
Showing 1 changed file with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,7 @@ public boolean execute(Connection connection, String sql, Object... params) thro
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
if (params != null) {
for (int i = 0; i < params.length; i++) {
Object param = params[i];
if (param instanceof String) {
statement.setString(i + 1, (String)param);
} else if (param instanceof Integer) {
statement.setInt(i + 1, (int)param);
} else if (param instanceof Double) {
statement.setDouble(i + 1, (double)param);
} else if (param instanceof Long) {
statement.setLong(i + 1, (long)param);
} else {
throw new JDBCClientException("Unsupported data type, type=" + param.getClass().getName());
}
}
}
setStatementParam(statement, params);
result = statement.execute();
statement.closeOnCompletion();
} catch (SQLException e) {
Expand All @@ -123,22 +108,7 @@ public ResultSet executeQuery(Connection connection, String sql, Object... param
PreparedStatement statement = null;
try {
statement = connection.prepareStatement(sql);
if (params != null) {
for (int i = 0; i < params.length; i++) {
Object param = params[i];
if (param instanceof String) {
statement.setString(i + 1, (String)param);
} else if (param instanceof Integer) {
statement.setInt(i + 1, (int)param);
} else if (param instanceof Double) {
statement.setDouble(i + 1, (double)param);
} else if (param instanceof Long) {
statement.setLong(i + 1, (long)param);
} else {
throw new JDBCClientException("Unsupported data type, type=" + param.getClass().getName());
}
}
}
setStatementParam(statement, params);
rs = statement.executeQuery();
statement.closeOnCompletion();
} catch (SQLException e) {
Expand All @@ -153,4 +123,25 @@ public ResultSet executeQuery(Connection connection, String sql, Object... param

return rs;
}

private void setStatementParam(PreparedStatement statement, Object[] params)
throws SQLException, JDBCClientException {
if (params != null) {
for (int i = 0; i < params.length; i++) {
Object param = params[i];
if (param instanceof String) {
statement.setString(i + 1, (String) param);
} else if (param instanceof Integer) {
statement.setInt(i + 1, (int) param);
} else if (param instanceof Double) {
statement.setDouble(i + 1, (double) param);
} else if (param instanceof Long) {
statement.setLong(i + 1, (long) param);
} else {
throw new JDBCClientException(
"Unsupported data type, type=" + param.getClass().getName());
}
}
}
}
}

0 comments on commit 4e80d8a

Please sign in to comment.