Menu

#474 allow overriding ccsid

Connection
open
nobody
JDBC (7)
5
2023-04-29
2023-03-03
No

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

Discussion

  • Jesse Gorzinski

    Jesse Gorzinski - 2023-04-29

    @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/ ?

     

Log in to post a comment.

MongoDB Logo MongoDB