dbjsp.jsp title> head> <% // Start try {connection conaction in tryright; resultTSet RS; / / load driver, below In order to load the MySQL driver class.Forname ("com.mysql.jdbc.driver); // Register the mysql driver DriverManager.RegisterDriver (new com.mysql.jdbc.driver ()); // Connect with the appropriate driver Go to the database string dburl = "JDBC: mysql: // localhost: 3306 / bookdb? Useunicode = true & characterencoding = GB2312
String dbuser = "dbuser"; string dbpwd = "1982023"; // Establish a database connection Con = Java.sql.driverManager.getConnection (DBURL, DBUSER, DBPWD); // Create a JDBC declaration Stmt = con.createstatement (); // Add new record stmt.executeUpdate ("INSERT INTO BOOKS (ID, Name, Title, Price) VALUES ('999', 'Tom', 'Tomcat Bible', 44.5)"); // Query RS = STMT. ExecuteQuery ("Select ID, Name, Title, Price from Books"); // Output Query Out.println ("
/ / Delete the newly added record stmt.executeUpdate ("delete from books where id = '999"); // Turns the database link rsclose (); stmt.close (); con.close ();}