Using mybatis to operate AS400 database

Keywords: Java Mybatis Oracle JDBC

Let's briefly talk about how to use [jt400.jar] to connect to the DB2 database on AS400.

jt400.jar resource, if you have AS400 client installed, refer to IBM official website

http://www-01.ibm.com/support/docview.wss?uid=swg21398042

Installation directory has jt400.zip, suffix can be used.

If you don't have AS400 client installed, download it yourself.

After introducing the jar package, go directly to the code description.

    public static Connection getAS400Connection() {
        Connection con = null;
        try {
            // register AS400
            java.sql.DriverManager.registerDriver(new com.ibm.as400.access.AS400JDBCDriver());
            con = DriverManager.getConnection("jdbc:as400://XXX.XXX.XXX.XXX;naming=system", "TEST001", "TEST001");
            System.out.println("Connected.");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return con;
    }

It's the same as calling JDBC later.

Mybatis section

1. Configure db.properties

oracle.driver=com.ibm.as400.access.AS400JDBCDriver
oracle.url=jdbc:as400://xxx.xxx.xxx.xxx;naming=system
oracle.username=TEST001
oracle.password=TEST001

2. Generating pojo, dao, mapper

Using generator Sqlmap-increase configuration is similar to the above

3.mybatis version (note)

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
   <!-- <version>3.4.6</version>-->
            <version>3.0.6</version>
        </dependency>

The latest version of mybatis will report errors when it is used.

1 Exception in thread "main" java.lang.IllegalAccessError: com.ibm.as400.access.AS400JDBCPreparedStatement.isClosed()Z
2     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
3     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
4     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
5     at java.lang.reflect.Method.invoke(Method.java:498)

There is no problem using 3.0.6 at present.

Exception in thread "main" java.lang.IllegalAccessError: com.ibm.as400.access.AS400JDBCPreparedStatement.isClosed()Z

Posted by mazman on Sat, 26 Jan 2019 05:12:15 -0800