We have the not entirely unique problem of needing to read/write to a table with the wrong ccsid https://stackoverflow.com/questions/37409928/db2-on-as400-encoding-issue-with-jt400
however we also need to write to the database and though getBytes works for getting Strings out ignoring the encoding setBytes does not and is rejected as the wrong type
Also this means we need to replace every getString/setString with getBytes and the conversion
I note that AS400JDBCConnectionImpl has a getConverter(int ccsid) and we could enhance this to allow an overridden ccsid
@Override
public ConvTable getConverter(int ccsid) throws SQLException {
if (this.forcedCcsid != null) {
return super.getConverter(this.forcedCcsid);
}
return super.getConverter(ccsid);
}
We can configure it with
@Override
public void setProperties(JDDataSourceURL dataSourceUrl, JDProperties properties,
AS400 as400, Properties info) throws SQLException {
super.setProperties(dataSourceUrl, properties, as400, info);
String p = info.getProperty(FORCED_CCSID);
if (p != null) {
forcedCcsid = Integer.parseInt(p);
}
}
I know we should fix our tables but as it's consistently wrong in thousands of tables and all applications that use the tables the reality is we are more likely to replace the mainframe than fix the problem.
We can easilly override the existing implementation and have our local fix but injecting it is harder as the AS400JDBCDriver has the implementation hard coded in the private method prepareConnection so we also need to copy the entirity of AS400JDBCDriver
Lastly we need to make sure the original driver isn't registered
while (true) {
Driver remove = DriverManager.getDriver("jdbc:as400://host");
DriverManager.deregisterDriver(remove);
}
I fully expect this to be rejected as a proposal but thought it might be useful to others
Apparently I missunderstood our problem is it more the QCCSID as described here https://www.ibm.com/support/pages/what-impact-changing-qccsid-shipped-65535-another-ccsid
We failed to set the qccsid but do set our ccsid on our tables
Last edit: Martin Sillence 2023-03-07
@msillence, we are in the process of migrating to GitHub. If you have an account there, do you mind opening an issue at https://github.com/IBM/JTOpen/ ?