Chapter 12 JSP JDBC Introduction n n Java
Chapter 12 JSP & JDBC
Introduction n n Java code calls JDBC library JDBC loads a driver Driver talks to a particular database Can have more than one driver -> more than one database Ideal: can change database engines without changing any application code Application JDBC Driver
JDBC API 與資料庫關係 Result. Set Prepared. Statement Result. Set Callable. Statement Connection 應用層 驅動程式層 Driver. Manager DB 2 Driver JDBC-ODBC Bridge My. SQL Driver
建立連接 n n n Connection為連接物件,它會連接Java到指定的資料庫。 我們使用Driver. Manager類別的get. Connection()靜態方 法來連接資料庫。取得連結物件。 jdbc: mysql: //localhost/My_Books是連接本地端的 My_Books資料庫。 root是My. SQL資料庫的管理者,登錄的密碼若設定為 322739。 Connection connection = Driver. Manager. get. Connection("jdbc: mysql: //localhost /My_Books", "root", "322739" );
- Slides: 14