Suppose there is a list name called People, its field structure and information content are as follows
ID (Beige VARCHAR) NAME (field type vARCHAR) SALY (Beige INT) 001 Wang Xiaoming 30000002 Chen Yongnian 35000003 Wang Xinguo 28000
A Connection CON 1 has been established, using SQL syntax new modification delete information 1. Add a data Add a number 004, name Liu Shaoqi, salary 31000 String InsertStr = "Insert Into People (ID, Name, Salary VALUES (?,?,?) "; prepaaredStatement PSTMT = Con.PrepareStatement (InsertStr); pstmt.setstring (1," 004 "); pstmt.setstring (2," Liu Shaoqi "); PSTMT.Setint (3,31000 ); pstmt.executeUpdate (); 2. Modify a data modification number 001 Wang Xiaoming's salary information, changed to 27000 string updatestr = "Update people set salary =? WHERE ID =?"; PreparedState pstmt = con.preparestatement (UpdateStr) PSTMT.Setint (1,27000); PSTMT.SetString (2, "001"); pstmt.executeUpdate (); 3. Delete a data deletion number 003 Wang Xinguo's information String Delstr = "DELETE from people where id =? "; PREPAREDSTATEMT PSTMT = Con.PrepareStatement (DELSTR); PSTMT.SetString (1," 003 "); pstmt.executeUpdate (); Second Driver, and this driver is actually made of the following method can be used 1. Add a new data Add a number 004, name Liu Shaoqi, salary 31000's information Statement Stmt = con.createment (ResultSet.Type_Scroll_Sensitive, ResultSet. Concur_updata); ResultSet RS = Stmt.executeQuery ("Select * from people); rs.movetoinsertrow (); rs.UpdateString ("ID", "004"); // or rs.UpdateString (1, "004); Represents the first field rs.UpdateString (" Name "," Liu Shaoqi "); rs.updateint (" Salary " , 31000); rs.insertRow (); 2. modify piece of data modification number 001 Xiaoming salary information into 27000 Statement stmt = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = stmt.executeQuery ( "SELECT * from people order by id"); rs.absolute (1); // move the cursor to the first Wang Xiaoming's information rs.UpdateInt ("Salary", 27000); rs.Updaterow (); 3. Delete A information deletion number 003 Wang Xinguo's information Statement Stmt = con.createstatement (ResultSet.Type_Scroll_Sensitive, ResultSet.concur_updata);