Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data truncation exception occurs when parameter exceeds field length [JDBC477] #516

Closed
firebird-automations opened this issue Feb 10, 2017 · 3 comments

Comments

@firebird-automations
Copy link

Submitted by: Beto Neto (betoneto.tbo)

Is related to CORE3559

When you create a statement with a parameter, and the parameter value length exceeds the field length occurs. Example:

Create table test(value varchar(6))

PreparedStatement ps = connection.prepareStatement("select * from test where value like ?");
ps.setString(1, "1234567"); >>>>> java.sql.DataTruncation: Data truncation
ps.executeQuery()

Now, if I hardcode the parameter in SELECT there is no exceptions.

PreparedStatement ps = connection.prepareStatement("select * from test where value like '1234567'");
ps.executeQuery()

@firebird-automations
Copy link
Author

Commented by: @mrotteveel

This is unfortunately a limitation of Firebird that parameters are limited to the length of the column they are compared against. It works with literals in a query because there the literal defines the length. The only viable workaround is to explicitly cast the parameter to a wider value (eg cast(? as varchar(100))).

In theory Jaybird could redeclare the variable to be wider, but that would only end up shifting the origin of the exception from Jaybird to Firebird, because Firebird would then generate a string truncation error anyway.

See also CORE3559.

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

status: Open [ 1 ] => Closed [ 6 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Author

Modified by: @mrotteveel

Link: This issue is related to CORE3559 [ CORE3559 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants