이상한 문제가 있습니다. 데이터베이스가 있는데 열의 값을 변경하려고합니다. 값은 Arraylist (timelist)에서 보호됩니다.Java : SQL 쿼리 : 열을 업데이트 한 후 rs.next()가 거짓입니다.
오른쪽 행에 값을 쓰려면 두 번째 Arrylist (이름 목록)가 있어야합니다. 따라서 이름 목록을 확인하고 이름을 찾는 것보다 데이터베이스의 첫 번째 행을 읽는 것이 좋습니다. 나는 timelist에서 일치하는 값을 가져 와서 데이터베이스의 "following_date"열에 이름에 일치하는 행에 기록합니다.
그리고 더 이상 항목이 없을 때까지 데이터베이스의 다음 행을 읽었습니다.
이상한 점은 데이터베이스에서 아무 것도 변경하지 않으면 while(rs.next())
부분이 작동한다는 것입니다. 예를 들어
는 :
ResultSet rs = statement.executeQuery("SELECT username FROM users");
while(rs.next()){
// read the result set
String name = rs.getString("username");
System.out.println("username = " + name); //liest die namen
}
}
이 이름 뒤에 나에게 모든 이름을 인쇄합니다. 그러나 테이블을 변경하면 while 루프가 끝납니다. (오류, 프로그램은 완료되지)
ResultSet rs = statement.executeQuery("SELECT username FROM users");
while(rs.next()){
// read the result set
String name = rs.getString("username");
System.out.println("username = " + name); //writes the name
//look, if name is in Arraylist "namelist"). if yes, than write the matching date from "timelist" into the database.
if (namelist.contains(name)){
System.out.println("name found: "+ name);
int listIndizi = namelist.indexOf(name); //get index
Long indiziDatum = (long) timelist.get(listIndizi); //get date from same Index
System.out.println(indiziDatum); // print date so i can see it is correct (which it is)
statement.executeUpdate("UPDATE users SET follows_date ="+ indiziDatum +" WHERE username = '"+name+"'"); //updates the follows_date column
}
}
이제 모든 것을 제외하고 잘 작동 while 루프는 제 1 통로 후 계속하지 않지만, 끝납니다.
매우 interersting, 난 몰랐어 AHA. 나는 이것을 시도 할 것이다. 고마워요 :) – aragonthebest
네, 이제 작동합니다. 동시에 2 명의 statemant를 별도의 변수로 선언 할 수 있습니까? – aragonthebest
질문을 취소하지 않습니까? 원하는만큼 명령문 오브젝트를 가질 수 있습니다. 문제의 (의사) 코드를 게시 할 수 있습니까? 그리고 대답을 받아들이는 것을 잊지 마세요 :-) – Guenther