Sử dụng INSERT qua Statement hoặc PreparedStatement (khuyến nghị).
Ví dụ Statement:
String sql = "INSERT INTO InsertDemo VALUES (1, 'John', 34)"; stmt.executeUpdate(sql);
Best practice: dùng PreparedStatement tránh SQL injection:
String sql = "INSERT INTO InsertDemo (Id, Name, Age) VALUES (?, ?, ?)"; PreparedStatement ps = conn.prepareStatement(sql); ps.setInt(1, 1); ps.setString(2, "John"); ps.setInt(3, 34); ps.executeUpdate();
Demo chạy thành công, SELECT xác nhận 2 hàng mới.