import pgjdbcng.PGDriver;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
public static void main(String[] args) {
String url = "jdbc:pgsql://localhost:5432/mydb";
String username = "myuser";
String password = "mypassword";
DriverManager.registerDriver(new PGDriver());
Connection connection = DriverManager.getConnection(url, username, password);
}
}
connection.setAutoCommit(false);
connection.begin();
String sql = "INSERT INTO users (name, email) VALUES (?, ?)";
PreparedStatement preparedStatement = connection.prepareStatement(sql);
preparedStatement.setString(1, "John Smith");
preparedStatement.setString(2, "john@example.com");
preparedStatement.execute();
connection.commit();
connection.rollback();
connection.close();