이 예외를 요청하지 :SQL 예외는, 생성 된 키는 내 코드의 한 부분에서 발생되는
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
String query = "Insert into ...";
try {
con = DriverManager.getConnection(...);
ps = con.prepareStatement(query, java.sql.Statement.RETURN_GENERATED_KEYS);
ps.executeUpdate(query);
rs = ps.getGeneratedKeys(); // Exception is here
}
while (resultset.next()) {
id = String.valueOf(resultset.getInt(1));
}
예외 :
생성 키를 요청하지합니다. 당신은 변수
id
에 (즉auto_increment
입니다)
내 목적은 새 레코드를 삽입한다) Statement.executeUpdate() 또는 위하여 Connection.prepareStatement (에 Statement.RETURN_GENERATED_KEYS를를 지정하고 첫 번째 필드 (id
)를 저장해야합니다.
@a_horse_with_no_name 나는 업데이트를 참조 @a_horse_with_no_name mysql을 –
를 사용합니다. –
두번째 예제는'prepareStatement()'호출을위한'java.sql.Statement.RETURN_GENERATED_KEYS' 파라미터를 포함하지 않습니다. –