pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feed[pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
14+ messages / 4 participants
[nested] [flat]
* [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2024-10-28 23:27 "tract-rob (@tract-rob)" <[email protected]>
0 siblings, 0 replies; 14+ messages in thread
From: tract-rob (@tract-rob) @ 2024-10-28 23:27 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Please read https://stackoverflow.com/help/minimal-reproducible-example
**Describe the issue**
Production code has been running error free since 2016, with the only change being regular driver upgrades. Upgrading from version 42.7.4 causes code to error...rolling back to 42.7.3 fixes the issue.
The code is binding a java.io.FileInputStream via Anorm 2.5.3. Looking at Anorm source code it looks like it's bound using PreparedStatement.setBinaryStream. The exception returned when the statement is executed is:
org.postgresql.util.PSQLException: Unable to bind parameter values for statement.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:394)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:517)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:434)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:194)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:155)
at com.zaxxer.hikari.proxy.PreparedStatementProxy.executeUpdate(PreparedStatementProxy.java:61)
at com.zaxxer.hikari.proxy.PreparedStatementJavassistProxy.executeUpdate(PreparedStatementJavassistProxy.java)
...
**Driver Version?**
42.7.4
**Java Version?**
openjdk version "1.8.0_412"
**OS Version?**
Amazon Linux 2
**PostgreSQL Version?**
15.8
**To Reproduce**
Steps to reproduce the behaviour:
1. Bind a java.io.FileInputStream object to e PreparedStatement using setBinaryStream.
2. call executeUpdate
**Expected behaviour**
A clear and concise description of what you expected to happen.
And what actually happens
For the last 8 years it's always successfully inserted the file into the database table. After driver upgrade, it just throws an error "Unable to bind parameter values for statement."
**Logs**
If possible PostgreSQL logs surrounding the occurrence of the issue
Additionally logs from the driver can be obtained adding
Using the following template code make sure the bug can be replicated in the driver alone.
```
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Properties;
public class TestNullsFirst {
public static void main(String []args) throws Exception {
String url = "jdbc:postgresql://localhost:5432/test";
Properties props = new Properties();
props.setProperty("user", "test");
props.setProperty("password", "test");
try ( Connection conn = DriverManager.getConnection(url, props) ){
try ( Statement statement = conn.createStatement() ) {
try (ResultSet rs = statement.executeQuery( "select lastname from users order by lastname asc nulls first") ){
if (rs.next())
System.out.println( "Get String: " + rs.getString(1));
}
}
}
}
}
```
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2024-10-29 10:01 ` "davecramer (@davecramer)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: davecramer (@davecramer) @ 2024-10-29 10:01 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
thanks for the report
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2024-10-29 11:26 ` "davecramer (@davecramer)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: davecramer (@davecramer) @ 2024-10-29 11:26 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
I cannot replicate this with
```
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
public class TestFileInputStream {
public static void main(String[] args) throws Exception {
try (Connection con = DriverManager.getConnection(
"jdbc:postgresql://localhost/test", "test", "")) {
con.createStatement().execute("create temporary table streamtable (bin bytea, str text)");
FileInputStream fis = new FileInputStream("./pom.xml");
try (PreparedStatement pstmt =
con.prepareStatement("INSERT INTO streamtable (bin,str) VALUES (?,?)")) {
pstmt.setBinaryStream(1, fis);
pstmt.setString(2, null);
pstmt.executeUpdate();
}
}
}
}
```
Do we have any idea what else is going on ?
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2024-11-12 15:10 ` "mEkdal (@mEkdal)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: mEkdal (@mEkdal) @ 2024-11-12 15:10 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Your program works with both 42.7.3 and 42.7.4 in my environment.
I have tweak the program a bit and the new test program only works with 42.7.3 and older.
The Statement causing the problem is one I have used a lot in many programs. so I wold prefer not to rewrite all of them
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2024-11-12 15:10 ` "mEkdal (@mEkdal)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: mEkdal (@mEkdal) @ 2024-11-12 15:10 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
package Jvakt;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class test07 {
public static void main(String[] args) throws Exception {
try (Connection con = DriverManager.getConnection(
"jdbc:postgresql://localhost/Jvakt", "test", "test")) {
Statement stmt = con.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_FORWARD_ONLY,ResultSet.CLOSE_CURSORS_AT_COMMIT );
stmt.executeQuery("create table streamtable (bin text, str text)");
}
}
}
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-02-04 20:15 ` "mEkdal (@mEkdal)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: mEkdal (@mEkdal) @ 2025-02-04 20:15 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
sadly the same problem remains in 42.7.5 :-(
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-02-06 11:53 ` "davecramer (@davecramer)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: davecramer (@davecramer) @ 2025-02-06 11:53 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
So I had a look at this today. I get a different error.
`Unknown value for ResultSet type`
Is that what you are seeing ?
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-02-06 13:08 ` "davecramer (@davecramer)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: davecramer (@davecramer) @ 2025-02-06 13:08 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Looks like
'''
// validation check for allowed values of resultset type
if (rsType != ResultSet.TYPE_FORWARD_ONLY && rsType != ResultSet.TYPE_SCROLL_INSENSITIVE && rsType != ResultSet.TYPE_SCROLL_SENSITIVE) {
throw new PSQLException(GT.tr("Unknown value for ResultSet type"),
PSQLState.INVALID_PARAMETER_VALUE);
}
'''
introduced in
https://github.com/pgjdbc/pgjdbc/commit/e0a614b79fc39a01fc0b7911955f5bcb47d0179b
is throwing the exception.
However looking at your code it seems that you have an error which this picks up. If
```
Statement stmt = con.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_FORWARD_ONLY,ResultSet.CLOSE_CURSORS_AT_COMMIT );
```
is what you have the concurrency and resultset type are in the wrong positions. It should be
```
Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT );
```
Let me know .
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-05-28 19:35 ` "vlsi (@vlsi)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: vlsi (@vlsi) @ 2025-05-28 19:35 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
@tract-rob if you still observe the issue, please report the full stacktrace. There should be a "caused by" message for `PSQLException: Unable to bind parameter values for statement.`
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-05-29 10:54 ` "mEkdal (@mEkdal)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: mEkdal (@mEkdal) @ 2025-05-29 10:54 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
I tested the 42.7.6 and the same problem that started in 42.7.4 was still present.
However, changing the order of the parameters from
_conn.createStatement(ResultSet.CONCUR_READ_ONLY,ResultSet.TYPE_FORWARD_ONLY,ResultSet.CLOSE_CURSORS_AT_COMMIT );_
to
_conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY,ResultSet.CLOSE_CURSORS_AT_COMMIT );_
makes it work!
Is this the solution?
In that case I will have to scan my programs and change all of them, because I suspect the "wrong" order is every where.
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-05-29 11:14 ` "davecramer (@davecramer)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: davecramer (@davecramer) @ 2025-05-29 11:14 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Seems that is the API https://docs.oracle.com/javase/8/docs/api/java/sql/Connection.html#createStatement-int-int-int-
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-05-29 11:27 ` "mEkdal (@mEkdal)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: mEkdal (@mEkdal) @ 2025-05-29 11:27 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
I suppose you are right.
I will use this order:
int resultSetType,
int resultSetConcurrency,
int resultSetHoldability
I think I copied it from a google hit way back, so I suppose more persons will have problem when the order is enforced,
I found I have about 35 programs to change, no big deal.
Thanks
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-06-09 08:43 ` "mEkdal (@mEkdal)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: mEkdal (@mEkdal) @ 2025-06-09 08:43 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Changed the order of the parameters of the createStatement to conn.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_READ_ONLY,ResultSet.HOLD_CURSORS_OVER_COMMIT );
and now it works.
^ permalink raw reply [nested|flat] 14+ messages in thread
* Re: [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream
@ 2025-06-09 09:17 ` "davecramer (@davecramer)" <[email protected]>
12 siblings, 0 replies; 14+ messages in thread
From: davecramer (@davecramer) @ 2025-06-09 09:17 UTC (permalink / raw)
To: pgjdbc/pgjdbc <[email protected]>
Thanks for the feedback
^ permalink raw reply [nested|flat] 14+ messages in thread
end of thread, other threads:[~2025-06-09 09:17 UTC | newest]
Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-10-28 23:27 [pgjdbc/pgjdbc] issue #3426: 42.7.4 introduced error when binding java.io.FileInputStream "tract-rob (@tract-rob)" <[email protected]>
2024-10-29 10:01 ` "davecramer (@davecramer)" <[email protected]>
2024-10-29 11:26 ` "davecramer (@davecramer)" <[email protected]>
2024-11-12 15:10 ` "mEkdal (@mEkdal)" <[email protected]>
2024-11-12 15:10 ` "mEkdal (@mEkdal)" <[email protected]>
2025-02-04 20:15 ` "mEkdal (@mEkdal)" <[email protected]>
2025-02-06 11:53 ` "davecramer (@davecramer)" <[email protected]>
2025-02-06 13:08 ` "davecramer (@davecramer)" <[email protected]>
2025-05-28 19:35 ` "vlsi (@vlsi)" <[email protected]>
2025-05-29 10:54 ` "mEkdal (@mEkdal)" <[email protected]>
2025-05-29 11:14 ` "davecramer (@davecramer)" <[email protected]>
2025-05-29 11:27 ` "mEkdal (@mEkdal)" <[email protected]>
2025-06-09 08:43 ` "mEkdal (@mEkdal)" <[email protected]>
2025-06-09 09:17 ` "davecramer (@davecramer)" <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox