(The design pattern of DAO (DataAccessObject) is the main design pattern in J2EE. The advantages of choosing DAO design: users do not need to know the detailed termination of the underlying layer, but only need to operate the interface; the distinction between the foreground and the background is terminated together; (in DAO only Requirement operation object); it is conducive to code reuse. (If the user needs to add new functions, I only need the general methods added in the DAO interface, and then terminate the user-added functions in DAOImpl, it will be very good. The terminal of the terminal increases user functions.) The overall design process of DAO: JSP---gt; DAO factory --gt; detailed terminal class --gt; detailed operation of terminal database 1. Terminal database connection class (DataBaseConnection.java) packageorg.zhao.DataBaseConnection.dbc;importjava.sql.
;publicclassDataBaseConnection{privatefinalStringDBDRIVER=com.mysql.jdbc.Driver;privatefinalStringDBURL=jdbc:mysql://localH/OST:3306/student;privatefinalStringDBUSER=root;privatefinalStringDBPASSWORD=root;privateConnectionconn=null;publicDataBaseConnection(){try{Class.forName (DBDRIVER);//conn=DriverManager.getConnection(DBURL,DBUSER,DBPASSWORD);conn=DriverManager.getConnection(jdbc:mysql://localH/OST:3306/student?user=rootpassword=root);}catch(Exceptione ){}}publicConnectiongetConnection(){returnthis.conn;}publicvoidclose(){try{this.conn.close();}catch(SQLExceptione){e.printStackTrace();}}}2. Define the function to be terminated by the project ......
The design pattern of struts dao.txt)