LoginSignup
1
0

More than 5 years have passed since last update.

JDBCでプリペアドステートメントを使った際に実行結果を見てみる

Last updated at Posted at 2018-05-22

JavaのJDBCを使う際にプリペアードステートメントを用いてSQL文を実行

String sql = "sql文";
stmt = conn.prepareStatement(sql);
stmt.setQueryTimeout(10);
stmt.setString(1, table);
stmt.setString(2, username);
int count = stmt.executeUpdate();//これで実行
stmt.close();
return (count > 0); // affected row(影響された列が1以上だったら、成功したよね?と解釈。)

affected rowの個数から判断するとは思いつきませんでしたね。

参考文献

https://stackoverflow.com/questions/24378270/how-do-you-determine-if-an-insert-or-update-was-successful-using-java-and-mysql
https://code.i-harness.com/ja/q/d4d07c

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0