|
Yep this, autocasting by the db...
Charles
On Wed, Oct 6, 2021 at 2:19 PM Niels Liisberg <nli@xxxxxxxxxxxxxxxxx>
wrote:
I think it is the auto-cast in Db2 that kicks in. And why statement 3
fails. For that it can not cast the current object value.
ons. 6. okt. 2021 kl. 21.58 skrev David Gibbs via JAVA400-L <
java400-l@xxxxxxxxxxxxxxxxxx>:
Folks:--
I just encountered a situation where JDBC allowed me to update rows in a
table where the values did not match the column definition.
As long as you use the setObject method, you can set a numeric column to
a string value and a character column with a numeric value.
The value contents have to match the column definition, but it doesn't
seem to care what the data type being passed in.
For instance:
You create a table as such ...
create table testtab1 (
decfield decimal(8,0),
charfield char(10)
)
... and then run code like this ...
try (
Connection conn = DriverManager.getConnection(url, props);
PreparedStatement stmt = conn.prepareStatement("insert into
dxglib/testtab1 (decfield,charfield) values(?,?)");
) {
stmt.setObject(1, 1);
stmt.setObject(2, "xyz");
stmt.executeUpdate();
stmt.setObject(1, "2");
stmt.setObject(2, 3);
stmt.executeUpdate();
stmt.setObject(1, "A");
stmt.setObject(2, 3);
stmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
.. the first two updates will work fine, but the 3rd will fail.
david
--
I'm riding in the American Diabetes Association's Tour de Cure to raise
money for diabetes research, education, advocacy, and awareness. You
can make a tax-deductible donation to my ride by visiting
https://mideml.diabetessucks.net.
You can see where my donations come from by visiting my interactive
donation map ... https://mideml.diabetessucks.net/map (it's a geeky
thing).
--
This is the Java Programming on and around the IBM i (JAVA400-L) mailing
list
To post a message email: JAVA400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/java400-l.
Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com
This is the Java Programming on and around the IBM i (JAVA400-L) mailing
list
To post a message email: JAVA400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/java400-l.
Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.