입력 insert와 비슷하다.

public class Program3 {

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
		
		String title = "TEST3";
		String content ="hahaha3";
		String files = "";
		int id = 6;
		
		String url = "jdbc:oracle:thin:@localhost:1521/xe";
		String sql = "" + 
				"  UPDATE NOTICE " + 
				"SET" + 
				"    TITLE = ?," + 
				"    CONTENT =?," + 
				"    FILES=?" + 
				"WHERE ID = ?";
		
			
		Class.forName("oracle.jdbc.driver.OracleDriver");
		Connection con = DriverManager.getConnection(url,"lec","0000");
		PreparedStatement st = con.prepareStatement(sql);
		st.setString(1, title);
		st.setString(2, content);
		st.setString(3, files);
		st.setInt(4, id);
		
		int result = st.executeUpdate();
		System.out.println(result);
		
		st.close();
		con.close();
			
	}
}

쿼리문 넣을때 띄어쓰기 조심해야한다.

출력값은 1로 잘나오고 , update도 잘되었다.

댓글남기기