| From: | Manav Kumar <mkumar(at)yugabyte(dot)com> |
|---|---|
| To: | pgsql-jdbc(at)lists(dot)postgresql(dot)org |
| Subject: | Don't see CLOSE packet been sent |
| Date: | 2025-12-04 13:37:21 |
| Message-ID: | CAPhCW+_N8emtusnO5B4bj3U3iFwH6BRSHMQZAexSAv3n7dkOog@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
Hi Team,
Wrote a simple below application to understand nature of CLOSE packet.
But i don't see the JDBC sending CLOSE packet. Any ideas what i can do see
CLOSE packet.
I'm compiling with:
javac -classpath /home/manavkumar/postgresql-42.7.1.jar sendClose.java && \
java -cp .:/home/manavkumar/postgresql-42.7.1.jar sendClose
```import java.sql.*;
public class sendClose {
public static void main(String[] args) {
Connection connection = null;
PreparedStatement pstmt1 = null, pstmt2 = null;
try {
// prepareThreshold=1 is crucial here
connection = DriverManager.getConnection("jdbc:postgresql://
10.150.3.175:5433/yugabyte?prepareThreshold=1", "yugabyte","yugabyte");
// ---------------------------------------------------------
// CHANGE 1: Use placeholders (?)
// This forces the driver to use Extended Query Protocol (Parse/Bind)
// and create a named statement (e.g., "S_1") on the server.
// ---------------------------------------------------------
pstmt1 = connection.prepareStatement("insert into t_ values (?, ?)");
pstmt1.setInt(1, 1);
pstmt1.setInt(2, 2);
// Execute twice to ensure the driver switches to server-prepare mode
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
pstmt1.execute();
// ---------------------------------------------------------
// CHANGE 2: Close the statement
// The driver now marks "S_1" as closed internally and queues the packet.
// ---------------------------------------------------------
pstmt1.close();
System.out.println("Statement 1 closed. Sending Statement 2 to flush the
buffer...");
// ---------------------------------------------------------
// CHANGE 3: Send ANY other traffic
// The driver will attach the buffered "CLOSE S_1" packet
// to the front of this new request.
// ---------------------------------------------------------
pstmt2 = connection.prepareStatement("SELECT 1");
pstmt2.execute();
pstmt2.close();
connection.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
```
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Manav Kumar | 2025-12-06 11:35:19 | Re: Don't see CLOSE packet been sent |
| Previous Message | Kennedy, Paul | 2025-10-03 18:58:31 | Documentation typo - jdbc connection parameters - preferQueryMode |