자바 프로그램에서 준비된 문을 사용하여 데이터베이스에 연결하고 테이블을 업데이트하려고합니다. 데이터베이스는 "데이터베이스"라고하며, 뷰에는 다른 뷰가있는 폴더가 있습니다. 내가 업데이트하려고하는 테이블 ("TABLE")입니다. 여기 내 코드는 다음과 같습니다.자바에서 준비된 SQL 문
public void updateTable(Map<String, String> mp) throws SQLException {
String URL = "jdbc:oracle:thin:@localhost:1500:orcl";
String USER = "user";
String PASS = "password";
Connection con = DriverManager.getConnection(URL, USER, PASS);
PreparedStatement updateTableName = null;
String updateString =
"update database.Views.TABLE " +
"set TABLENAME = ? " +
"where TABLENAME = ?";
try {
con.setAutoCommit(false);
updateTableName = con.prepareStatement(updateString);
for (Map.Entry<String, String> e : mp.entrySet())
{
updateTableName.setString(1, e.getValue());
updateTableName.setString(2, e.getKey());
updateTableName.executeUpdate();
con.commit();
}
} catch (SQLException e) {
if (con != null)
{
try {
System.err.print("Transaction is being rolled back");
con.rollback();
} catch (SQLException excep) {
}
}
} finally {
if (updateTableName != null)
{
updateTableName.close();
}
con.setAutoCommit(true);
}
con.close();
}
코드를 실행할 때마다 "트랜잭션이 롤백 중입니다."라는 메시지가 나타납니다. try 문에 어떤 오류가 있습니까? 미리 감사드립니다!
EDIT : 예외를 인쇄하도록 변경하면 ORA-00971 : SET 키워드가 누락됩니다.
대신 바로 잡기, 인쇄/로깅 예외가 전자에게 약간의 단서를 GIV 수 – kosa
디를 예외를 읽었 니? – SLaks