《盜賊遺產2》圖文攻略 全流程解謎及BOSS戰圖文攻略
阿新 • • 發佈:2022-05-09
public class JdbcPractice { @Test public void testInsert() throws SQLException, ClassNotFoundException { // 1. 註冊驅動 Class.forName("com.mysql.jdbc.Driver"); // 2. 獲取Connection物件 Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/company_db", "root", "root"); // 3. 獲取Statement物件 Statement stmt = connection.createStatement(); // 4. 獲取結果集 String username = "zhangsan"; String password = "345678"; String balance = "1000"; int i = stmt.executeUpdate("INSERT INTO tb_user(`username`, `password`, `balance`) " + "VALUES('" + username + "', '" + password + "', " + balance + ")"); // 5. 處理結果集 System.out.println(i); // 6. 釋放資源 stmt.close(); connection.close(); } } 3.1.2 刪除資料 public class JdbcPractice { @Test public void testDelete() throws SQLException, ClassNotFoundException { // 1. 註冊驅動 Class.forName("com.mysql.jdbc.Driver"); // 2. 獲取Connection物件 Connection connection = DriverManager.getConnection( "jdbc:mysql://localhost:3306/company_db", "root", "root"); // 3. 獲取Statement物件 Statement stmt = connection.createStatement(); // 4. 獲取結果集 String id = "3"; int i = stmt.executeUpdate("DELETE FROM tb_user WHERE id=" + id); // 5. 處理結果集 System.out.println(i); // 6. 釋放資源 stmt.close(); connection.close(); } }