執行 INSERT 陳述式 • String sql = "INSERT INTO users (name, email) VALUES (?, ?)"; • try (Connection connection = DriverManager.getConnection(url, username, password); • PreparedStatement statement = connection.prepareStatement(sql)) { • statement.setString(1, "John"); • statement.setString(2, "
[email protected]"); • int rowsInserted = statement.executeUpdate(); • if (rowsInserted > 0) { • System.out.println("新增成功"); • } • } catch (SQLException e) { • e.printStackTrace(); • }