Thiru
Thiru

Reputation: 1

HELIDON Support for DB2 and SQL server database

Able to connect to Oracle 19c database using https://helidon.io/docs/latest/#/mp/extensions/02_cdi_datasource-ucp How to connect to DB2 and SQL server databases - need sample drivers and connection properties

Upvotes: 0

Views: 206

Answers (2)

Thiru
Thiru

Reputation: 1

I wanted to configure the data sources through application.yaml file. For Microsoft SQL, the below config works.

javax:
   sql:
      DataSource:
         TEST:
            dataSourceClassName: com.microsoft.sqlserver.jdbc.SQLServerDataSource
            dataSource:
               URL: jdbc:sqlserver://hostname:1400;databasename=dbname
               user: testuser
               password: testuser

And for DB2:

javax:
   sql:
      DataSource:
         TEST:
            dataSourceClassName: com.ibm.db2.jcc.DB2SimpleDataSource
            dataSource:
               user: user1
               password: user1
               databaseName: dbname
               serverName: localhost
               portNumber: 40000
               currentSchema: currentSchemaName
               driverType: 4
               progressiveStreaming: 2

And in the Java class, these data sources can be accessed with:

  @Inject
   @Named("TEST")
   private DataSource          dataSource;

Upvotes: 0

Daniel Kec
Daniel Kec

Reputation: 559

One way is to use original datasource:

    <dependency>
        <groupId>com.ibm.db2</groupId>
        <artifactId>jcc</artifactId>
        <version>11.5.6.0</version>
    </dependency>

And register it as a bean yourself:

@ApplicationScoped
public class MyBean {

    @Produces
    @ApplicationScoped
    public javax.sql.DataSource db2DataSource() {
        DB2SimpleDataSource ds = new DB2SimpleDataSource();
        ds.setDatabaseName("dbkec1");
        ds.setDescription("Some cool db");
        ds.setUser("dan");
        ds.setPassword("pass");
        return ds;
    }

}

Or use HikariCP datasource with DB2 driver https://helidon.io/docs/latest/#/mp/extensions/02_cdi_datasource-hikaricp

Upvotes: 0

Related Questions