업데이트 된 영향을받는 행의 ID를 반환하려고했습니다. 궁금하네요, 왜 내가 이걸 돌려서 ResultSet을 얻지 못했을까요? (기본 키는 괜찮을 겁니다.) Statement.RETURN_GENERATED_KEYS
을 설정 했는데요? 가장 최근의 jTDS 드라이버 1.3.0을 사용하여 Microsoft SQL Server에 연결합니다.결과 문을 update 문에서 반환 하시겠습니까?
try
{
PreparedStatement pst = SQL.getConnection().prepareStatement(qry, Statement.RETURN_GENERATED_KEYS);
pst.setString(1, someValue);
pst.setString(2, someOtherValue);
int affectedRows = pst.executeUpdate();
System.out.println(affectedRows); //to make sure whether the query updated anything
ResultSet rs = pst.getGeneratedKeys();
if (rs.next())
{
System.out.println(rs.getInt(1));
}
} catch (Exception e) {
e.printStacktTrace();
}
여기에 어떤 제안이 있습니까?
쿼리 란 무엇입니까? 생성되는 키는 무엇입니까? – Thilo
은 자동 증분 열을 검색하려고 시도하는 핵심 요소입니까 ?? – PermGenError
어떤 오류가 있습니까? 'rs' null? 'rs.next()'가 없습니까? 'rs.getInt (1)'실패합니까? 의미있는 원조를 원한다면 좀 더 자세하게 말하십시오. – SJuan76