TAILIEUCHUNG - My SQL and Java Developer’s Guide phần 7

Các đặc điểm kỹ thuật JDBC và Connector / J cung cấp truy cập đến một số phương pháp cho phép một ứng dụng truy cập thông tin về cơ sở dữ liệu cũng như thông tin về một đối tượng ResultSet. Trong chương này, chúng tôi bao gồm một số các phương pháp phổ biến hơn | Bean-Managed Persistence 241 public int ejbCreate String username String password throws CreateException RemoteException public void ejbPostCreate String course String instructor public int ejbLoad throws RemoteException public int ejbStore throws RemoteException public int ejbRemove throws RemoteException public String findByPrimaryKey throws RemoteException ejbCreate We can use the ejbCreateO method when we want to insert a new row into the database. To accomplish this we need to access the database check to see if the row already exists and either insert a row into the table or throw an exception. The code might look like this public int ejbCreate String username String password throws CreateException RemoveException InitialContext ctx new InitialContext DataSource ds DataSource java comp env jdbc AccountsDB Connection conn PreparedStatement stmt SELECT FROM acc_acc WHERE username and password 1 username 2 password ResultSet rs duplicateKey if duplicateKey stmt INSERT INTO acc_acc null 1 username 2 password null new Timestamp new Date .getDate L242 EJBs with MySQL catch Exception ex throw new ejbCreate Error ex if duplicateKey throw new return null As the preceding code shows we are responsible for doing all of the database work in a bean-managed persistence mode. ejbLoad In the ejbLoad method the code has to load all of the fields for the row associated with a particular primary key. For example public void ejbLoad throws boolean found false try InitialContext ctx new InitialContext DataSource ds DataSource java comp env jdbc AccountsDB Connection conn PreparedStatement stmt SELECT

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.