JDBC: Communication interface function
1.mysql driver (JDBC): The driver is placed in the project library or tomcat/lib, MySQL website jdbc includes the JDBC driver and API2.JDBC API: Database access interface 3.jsp and database access 4. Process Load driver (operation of which database (MySQL Oracle) class.forname (DRIVER);p ublicstaticfinalstring driver= "Org.gjt.mm.mysql.Driver";---> Create link (connect link to database, via URL) drivermanager.getconnection (url,username,username),----> Create action SQL statement Statement interface, instantiated by the Createstatement () method of the Connection interface, Statement.executeupdate (SQL) to manipulate the database (-PreparedStatement interface -is statement sub-interface, is a preprocessing operation, and directly using statement, is to prepare a SQL statement in the data table, but the specific content of this SQL statement is not set, but after the setting, that is, occupy this location waiting for user settings -String sql= "insert INTO newtable (name,sex) VALUES (?,?)"; -pstatement=conn.preparestatement (SQL); Instantiation -pstatement.setstring (1, name); -pstatement.setstring (2, Sex); -pstatement.executeupdate (); -NOTE: It is not recommended to use statement to manipulate the database in development, but to use PreparedStatement because statement is a complete SQL statement -processing Big Data Objects-- Must use PreparedStatement) ---> Accept query Results-ResultSet interface-Accept the queried records and display the content, in development to limit the number of queries -ResultSet rset= Statement.executequery (SQL);
SQL+TOMCAT+JSP Environment Construction