PS: Query is relatively complex, to deal with the result set, adding and deleting Gerze not.
1 PackageIt.cast.jdbc;2 3 Importjava.sql.Connection;4 ImportJava.sql.ResultSet;5 Importjava.sql.SQLException;6 Importjava.sql.Statement;7 8 Public classCRUD {9 Ten /** One * @paramargs A * @throwsclassnotfoundexception - * @throwsSQLException - */ the Public Static voidMain (string[] args)throwsSQLException, ClassNotFoundException { - Delete (); - - } + - //Delete + Static voidDelete ()throwsSQLException, ClassNotFoundException { A atConnection conn =NULL; -Statement st =NULL; -ResultSet rs =NULL; - //2. Establish a connection -conn =jdbcutils.getconnection (); - in //3. Create a statement -St =conn.createstatement (); to +String sql = "Delete from user where name= ' name1 '"; - the //4. Execute the statement * inti =st.executeupdate (SQL); $ Panax NotoginsengSystem.out.println ("i=" +i); - the //6. Releasing Resources + Jdbcutils.free (RS, St, conn); A } the + //Modify - Static voidUpdate ()throwsSQLException, ClassNotFoundException { $ $Connection conn =NULL; -Statement st =NULL; -ResultSet rs =NULL; the //2. Establish a connection -conn =jdbcutils.getconnection ();Wuyi the //3. Create a statement -St =conn.createstatement (); Wu -String sql = "Update user set MONEY=MONEY+10"; About $ //4. Execute the statement - inti =st.executeupdate (SQL); - -System.out.println ("i=" +i); A + //6. Releasing Resources the Jdbcutils.free (RS, St, conn); - } $ the the //New the Static voidCreate ()throwsSQLException, ClassNotFoundException { the -Connection conn =NULL; inStatement st =NULL; theResultSet rs =NULL; the //2. Establish a connection Aboutconn =jdbcutils.getconnection (); the the //3. Create a statement theSt =conn.createstatement (); + -String sql = "INSERT into user (Name,birthday,money) VALUES (' name1 ', ' 1997-01-01 ', 4000)"; the Bayi //4. Execute the statement the inti =st.executeupdate (SQL); the -System.out.println ("i=" +i); - the //6. Releasing Resources the Jdbcutils.free (RS, St, conn); the } the -}CRUD