私は選択を持っている場合、これは動作します?なぜwhileループでexcutedことupdateSqlができない
public static void main(String[] args){
try{
Connection conn = DriverManager.getConnection("jdbc:oracle:XXXXX", "username", "psw");
Statement stm = conn.createStatement();
String selectSql="select h.id, h.user_id,h.start_time,h.end_time,h.start_date,h.end_date, a.time_zone from hos_driving_log h left join user_info ua on h.user_id= ua.user_id left JOIN account a on a.acct_id = ua.acct_id";
ResultSet ress = stm.executeQuery(selectSql);
while(ress.next()){
int id = ress.getInt("id");
String user_id = ress.getString("user_id");
long start_time = ress.getLong("start_time");
long end_time = ress.getLong("end_time");
int start_date = ress.getInt("start_date");
int end_date = ress.getInt("end_date");
String time_zone = ress.getString("time_zone");
System.out.println(id+" "+user_id+" "+start_time+" "+end_time+" "+start_date+" "+end_date+" "+time_zone);
}
}catch(SQLException e){
e.printStackTrace();
}
//Close the resources - Done automatically by try-with-resources
}
出力:
1 testuserを20151025021324 20151026024135 0 0 GMT-12:00
を 2 hostest 20151026024135 20151022080352 0 GMT-07:00
24 stress0101 20151208075641 20151208075717 0ヌル
88 123 0 0 20151224130803 20151224085208 Cヌル
C89 123 C 20151224130916 20151224130922 0 0ヌル
90 123 C 20151224130917 20151224130923 0 0ヌル
91 123 C 20151224130918 20151224130924 0 0ヌル
92 123 20151224130925 0 0ヌル
しかし、私はしたいときループでアップデート:
:try{ Connection conn = DriverManager.getConnection("jdbc:oracle:XXXXX", "username", "psw"); Statement stm = conn.createStatement(); String selectSql="select h.id, h.user_id,h.start_time,h.end_time,h.start_date,h.end_date, a.time_zone from hos_driving_log h left join user_info ua on h.user_id= ua.user_id left JOIN account a on a.acct_id = ua.acct_id"; ResultSet ress = stm.executeQuery(selectSql); while(ress.next()){ int id = ress.getInt("id"); String user_id = ress.getString("user_id"); long start_time = ress.getLong("start_time"); long end_time = ress.getLong("end_time"); int start_date = ress.getInt("start_date"); int end_date = ress.getInt("end_date"); String time_zone = ress.getString("time_zone"); System.out.println(id+" "+user_id+" "+start_time+" "+end_time+" "+start_date+" "+end_date+" "+time_zone); start_date = getDrivingLogShortTypeDate(start_time, time_zone); end_date = getDrivingLogShortTypeDate(end_time, time_zone); String updateSql = "update hos_driving_log set start_date = "+ start_date+",end_date = "+end_date+" where id="+id; int i = stm.executeUpdate(updateSql); System.out.println(updateSql); } }catch(SQLException e){ e.printStackTrace(); } //Close the resources - Done automatically by try-with-resources
...それが唯一の更新を行います
45 CO 2 stress0096 20151222090816 20151222091436 20151222 20151222 GMT + 08:START_DATE = 20151222、END_DATE = 20151222 ID = 45
なぜそれが1回の更新後に停止されるセット00
更新hos_driving_log?すべての行を更新するにはどうすればよいですか?
あなたの投稿の書式設定に_some_努力をしてください。 UIを使用する方法がわからない場合は、ヘルプセンターでお手伝いできます。 –
45は最初の出力にないので、まったく異なるデータのようです。データは変更されましたか?または、別のデータベースまたはスキーマに接続していますか? –
@Jolie更新ステートメントが追加された後、printステートメントが1回だけ印刷されることを意味しますか?あなたはデータベースをチェックしましたか? – pahan