MCPcopy Create free account
hub / github.com/diyhi/bbs / executeStatement

Method executeStatement

src/main/java/cms/utils/SqlScriptRunner.java:267–319  ·  view source on GitHub ↗

执行语句 @param command 命令 @throws SQLException

(String command)

Source from the content-addressed store, hash-verified

265 * @throws SQLException
266 */
267 private void executeStatement(String command) throws SQLException {
268 boolean hasResults = false;
269 Statement statement = connection.createStatement();
270 statement.setEscapeProcessing(escapeProcessing);
271 String sql = command;
272 if (removeCRs) {
273 sql = sql.replaceAll("\r\n", "\n");
274 }
275 if (stopOnError) {
276 hasResults = statement.execute(sql);
277 if (throwWarning) {
278 // In Oracle, CRATE PROCEDURE, FUNCTION, etc. returns warning
279 // instead of throwing exception if there is compilation error.
280 SQLWarning warning = statement.getWarnings();
281 if (warning != null) {
282 throw warning;
283 }
284 }
285 } else {
286 try {
287 hasResults = statement.execute(sql);
288 } catch (SQLException e) {
289 String message = "执行语句错误: " + command + ". 原因: " + e;
290 printlnError(message);
291
292 if (throwException) {
293 SQLWarning warning = statement.getWarnings();
294 if (warning != null) {
295 try {
296 statement.close();
297 } catch (Exception e2) {
298 if (logger.isErrorEnabled()) {
299 logger.error("当错误抛出异常时执行语句关闭Statement错误",e2);
300 }
301 // Ignore to workaround a bug in some connection pools
302 }
303 throw e;
304 }
305
306 }
307
308 }
309 }
310 printResults(statement, hasResults);
311 try {
312 statement.close();
313 } catch (Exception e) {
314 if (logger.isErrorEnabled()) {
315 logger.error("执行语句关闭Statement错误",e);
316 }
317 // Ignore to workaround a bug in some connection pools
318 }
319 }
320 /**
321 * 打印结果
322 * @param statement Statement对象

Callers 2

executeFullScriptMethod · 0.95
handleLineMethod · 0.95

Calls 3

printlnErrorMethod · 0.95
printResultsMethod · 0.95
setEscapeProcessingMethod · 0.80

Tested by

no test coverage detected