Java Database Basic Operation 1, Java Database Operation Basic Process 2 Database connection 1, acquired database connection 1) Take DRIVERMANAGER to take the database connection example string classname, url, uid, pwd; classname = "Oracle.jdbc.driver.Orcledriver"; URL = "JDBC: Oracle: Thin: @ 127.0.0.1: Thin: @ 127.0.0.1: 1521: ORASVR; uid = "system"; PWD = "manager"; class.forname (classname); connection cn = drivermanager.getConnection (URL, UID, PWD); 2) Way with JNDI (Java Naming and Directory Service) Example String JNDI = "JDBC / DB"; Context CTX = (Context) New InitialContext (). Lookup ("Java: Comp / ENV"); DataSource DS = (Datasource) CTX.lookup (JNDI); Connection CN = DS. GetConnection (); Multi-Delivery SQL Statement 1 in JSP 1) Execute SQL Statement String SQL; Statement SM = Cn.createStatement (); Sm.executeQuery (SQL); // Execute Data Quych Swords (SELECT) SM .executeUpdate (SQL); // Perform data update statement (delete, update, insert, drop, etc.) statement.close (); 2) Execute SQL statements String SQL; SQL = "Insert Into User (ID, NAME) with preparedStatement VALUES (?,?) "; PreparedStateMe NT ps = cn.preparestatement (SQL); ps.setint (1, xxx); ps.setstring (2, xxx); ... resultSet RS = ps.executeQuery (); // query int C = ps.executeUpdate ); // update 3, process the execution result query statement, return the record set RESULTSET update statement, return the number, indicating that the number of records affected by the update Resultset 1, next (), move the cursor to move, if successful returns true Otherwise returning false 2, getint ("id") or getSting ("name"), returns the value of a field under the current cursor 4, release connection cnclose (); general, turn off the resultTset first, then close Statement (or PreparedStatement); Finally close the Connection can scroll, update record set 1, create scrollable, updated statement SM =