2014-10-22 3 views
0

xampp을 사용하여 원격 mysql 테이블에서 업데이트를 수행하려고합니다. 나는 이것을 RMI 애플리케이션으로 구현했다. 나는 또한 잘 작동하는 addDoctor 메소드를 구현했다. 하지만 클라이언트 GUI에서 updateDoctor 메서드를 실행할 때 레코드가 업데이트되었지만 (오류 없음) 데이터베이스를 확인할 때 변경 내용이 반영되지 않는다고 말합니다.원격 mysql 테이블에서 업데이트 할 수 없습니다

public void updateDoctor(int id, String name) throws RemoteException{ 
    PreparedStatement ps = null; 
    try{ 
     Class.forName("com.mysql.jdbc.Driver"); 
     Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/hospital_db", "root", ""); 
     String sql = "UPDATE doctor SET doctor_name=? WHERE doctor_id=? "; 
     ps = con.prepareStatement(sql); 
     ps.setInt(1, id); 
     ps.setString(2, name); 
     ps.executeUpdate(); 
     con.commit(); 
     System.out.println("Updated!"); 
    } 
    catch(SQLException e){ 
     System.out.println("Error: "+e); 
    } 
    catch(ClassNotFoundException e){ 
     System.out.println("Error: "+e); 
    } 

} 
+0

는'doctor_id' 값이 테이블에 존재 하는가? 'executeUpdate'의 반환 값을 정수에 할당하여 영향을받는 행의 수를 확인할 수 있습니다. – manouti

+0

"업데이트 됨"이 켜져있는 경우 예외가 없다는 메시지 만 나타납니다. 그것은 수술이 성공적 이었다는 것을 의미하지는 않습니다. –

답변

2

시도 :

ps.setString(1, name);  
ps.setInt(2, id); 
+0

오, 예, 바보 같은 오류! 감사 – user3162879

관련 문제