Creating XA DataSource to DB2 on JBoss - db2

I trying to configure an XA DB2 DataSource, xa-datasource (based on http://community.jboss.org/wiki/SetUpADB2Datasource) using com.ibm.db2.jcc.DB2XADataSource class (local-tx-datasource works using the com.ibm.db2.jcc.DB2Driver). The target server is DB2 Connect V9.7
Actual xa-datasource config:
<xa-datasource>
<jndi-name>jdbc/DB2ServerDS</jndi-name>
<use-java-context>false</use-java-context>
<track-connection-by-tx>true</track-connection-by-tx>
<xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>
<xa-datasource-property name="URL">jdbc:db2://db2server:50000/FINDB</xa-datasource-property>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.DB2ExceptionSorter</exception-sorter-class-name>
<xa-datasource-property name="DriverType">4</xa-datasource-property>
<check-valid-connection-sql>SELECT * FROM ACC.SETTINGS 1=2</check-valid-connection-sql>
<user-name>findbuser</user-name>
<password>findbuser</password>
<min-pool-size>2</min-pool-size>
<max-pool-size>10</max-pool-size>
<blocking-timeout-millis>10000</blocking-timeout-millis>
<type-mapping>DB2</type-mapping>
<no-tx-separate-pools/>
</xa-datasource>
and the following jar in the JBoss node lib directory:
db2umplugin.jar
db2policy.jar
db2dbgm.jar
db2jcc_license_cu.jar
db2jcc.jar
db2jcc4.jar
db2java.zip
db2jcc_license_cisuz.jar
but i'm getting the error:
Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][10389][12245][3.57.82] Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError: no db2jcct2 in java.library.path: ERRORCODE=-4472, SQLSTATE=null
The driver for XA is trying to use native libraries, despite the fact that i'm using a JDBC Type 4 driver.
Why is the driver trying to use native libraries? Is there anything i need to add to my config?

The solution is not to use the URL to specify the connection settings.
<xa-datasource>
<jndi-name>jdbc/DB2ServerDS</jndi-name>
<use-java-context>false</use-java-context>
<track-connection-by-tx>true</track-connection-by-tx>
<xa-datasource-class>com.ibm.db2.jcc.DB2XADataSource</xa-datasource-class>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.DB2ExceptionSorter</exception-sorter-class-name>
<xa-datasource-property name="ServerName">db2server</xa-datasource-property>
<xa-datasource-property name="PortNumber">50000</xa-datasource-property>
<xa-datasource-property name="DatabaseName">FINDB</xa-datasource-property>
<xa-datasource-property name="DriverType">4</xa-datasource-property>
<xa-datasource-property name="User">findbuser</xa-datasource-property>
<xa-datasource-property name="Password">findbuser</xa-datasource-property>
<xa-datasource-property name="DriverType">4</xa-datasource-property>
<check-valid-connection-sql>SELECT * FROM ACC.SETTINGS 1=2</check-valid-connection-sql>
<user-name>findbuser</user-name>
<password>findbuser</password>
<min-pool-size>2</min-pool-size>
<max-pool-size>10</max-pool-size>
<blocking-timeout-millis>10000</blocking-timeout-millis>
<type-mapping>DB2</type-mapping>
<no-tx-separate-pools/>
</xa-datasource>
Credit to http://dev.wavemaker.com/forums/?q=node/3127
The correct JARs are
db2jcc_license_cu.jar
db2jcc4.jar
db2jcc_license_cisuz.jar
Should you get an error like:
org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (com.ibm.db2.jcc.am.SqlException: DB2 SQL Error: SQLCODE=-5042, SQLSTATE= , SQLERRMC= ;1208;FINDBUSER;FINDB;QDB2; ; ; ;1208; , DRIVER=4.7.85)
check http://www-01.ibm.com/support/docview.wss?uid=swg21405243&myns=swgimgmt&mynp=OCSSEPGG&mync=R for the solution.
I hope this saves others some frustration and time.

Related

Wildfly tries to open wrong server

While accesing a remote database Wildfly is not able to connect to it, it tries to access COMPNAME (my computer's name) as if it was the selected database instead of the one defined on datasource, that of course doesn't exist.
I have used the same conection properties on datasource to access database with SQL Server Management Studio and it works perfectly, the standalone configuration is the same as in my old computer where it worked.
This is the datasource:
<datasource jta="true" jndi-name="java:/SQLDESTINATION" pool-name="SQLDESTINATION" enabled="true" use-ccm="true">
<connection-url>jdbc:sqlserver://urlthatworks:1433;DatabaseName=DB_NAME</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqljdbc4.jar</driver>
<security>
<user-name>userok</user-name>
<password>passok</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"/>
<background-validation>true</background-validation>
</validation>
</datasource>
And here is wildfly log:
2019-09-27 13:29:53,126 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ServerService Thread Pool -- 71) javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/SQLDESTINATION
2019-09-27 13:30:07,483 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (ServerService Thread Pool -- 71) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: IJ031084: Unable to create connection
.......
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open server "COMPNAME" requested by the login. The login failed.
So problem is that instead of trying to get to "DB_NAME" it is trying to access "COMPNAME"
Difference that I guess shouldn't matter is old computer was using windows 7 and this one windows 10 and in old computer wildfly folder was under C:\Users\myusername\wildfly-10.1.0.Final folder while in new one it is in D:\wildfly-10.1.0.Final
Try databaseName=DB_NAME instead of DatabaseName=DB_NAME.
I managed to get it work by changing the folder to C:\Users\myusername\wildfly-10.1.0.Final although this doesn't explain why on D: it would try to overwrite the server name with my computer name.

Database configuration with WildFly

I intend to configure postgresql in my app, but I don't want to manage access to my db through WildFly. Is it possible to avoid this approach and to chose another way but with jndi?
If you want to connect a postgresql database without abstraction layer such as wildFly, you can use simply jdbc (https://jdbc.postgresql.org/about/about.html) :
PostgreSQL JDBC Driver (PgJDBC for short) allows Java programs to
connect to a PostgreSQL database using standard, database independent
Java code. Is an open source JDBC driver written in Pure Java (Type
4), and communicates in the PostgreSQL native network protocol.
If you prefer a lightweight ORM (Object Relational Mapping), I would advise activejdbc (http://javalite.io/activejdbc).
Here you can find the configuration of Wildfly Wildfly datasource configuration . The datasource can be access with jndi. You have to replace the example-jdbc-driver with postgres driver.
Bellow is my example of configuration of datasource for IBM-informix
<datasource jndi-name="java:jboss/datasources/mvpdb" pool-name="mvpdbpool">
<connection-url>jdbc:informix-sqli://mars.bza-intern.de:30020/demomvp:informixserver=tcpmars;DB_LOCALE=de_DE.8859-1;IFX_LOCK_MODE_WAIT=10;</connection-url>
<driver>informix</driver>
<transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>3</max-pool-size>
<prefill>true</prefill>
</pool>
<security>
<user-name>abcd</user-name>
<password>efgh</password>
</security>
<statement>
<prepared-statement-cache-size>32</prepared-statement-cache-size>
<share-prepared-statements>true</share-prepared-statements>
</statement>
</datasource>
The datasource can be access ( Spring context ):
with Java Configuration
#Bean(name = "mvpds", autowire = Autowire.BY_NAME)
public DataSource Mvpds() {
logger.info("Mvpds-bean");
final JndiDataSourceLookup dsLookup = new JndiDataSourceLookup();
dsLookup.setResourceRef(true);
DataSource ds = dsLookup.getDataSource("java:jboss/datasources/mvpdb");
return ds;
}
or XML definition
<bean id="mvpds" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:jboss/datasources/mvpdb</value></property>
</bean>
The question was not correct because of lack of knowledge. The promblem is that no way to configure db without WildFly but with jndi. Jndi is an instrument WildFly uses to find a datasourse:)

SpringBoot application in Tomcat server: PostgreSQL Driver Not Found

I am using Spring boot application to develop Postgresql based application using Eclipse IDE(openjdk version 1.8.0_151)
I have configured gradle as follows:
compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc'
I am using Spring JdbcTemplate to access database. Everything works perfect in Eclipse IDE. I want to create a war file and deploy into Tomcat 9 server. But unfortunately, I got the following error message:
org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is java.sql.SQLException: No suitable driver found for jdbc:postgresql://server:5432/db_pm
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:80)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:619)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:684)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:716)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:726)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:776)
at org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:853)
at com.kpaudel.pm.PasswordManagerDAO.getSimilarServices(PasswordManagerDAO.java:108)
at com.kpaudel.pm.PasswordManagerDAO$$FastClassBySpringCGLIB$$482fbdc8.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.kpaudel.pm.PasswordManagerDAO$$EnhancerBySpringCGLIB$$8f3e1618.getSimilarServices(<generated>)
at com.kpaudel.telegram.bots.PasswordManagerBot.onUpdateReceived(PasswordManagerBot.java:87)
at java.util.ArrayList.forEach(ArrayList.java:1255)
at org.telegram.telegrambots.generics.LongPollingBot.onUpdatesReceived(LongPollingBot.java:27)
at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$HandlerThread.run(DefaultBotSession.java:301)
Caused by: java.sql.SQLException: No suitable driver found for jdbc:postgresql://server:5432/db_pm
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriverManager(DriverManagerDataSource.java:153)
at org.springframework.jdbc.datasource.DriverManagerDataSource.getConnectionFromDriver(DriverManagerDataSource.java:144)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnectionFromDriver(AbstractDriverBasedDataSource.java:196)
at org.springframework.jdbc.datasource.AbstractDriverBasedDataSource.getConnection(AbstractDriverBasedDataSource.java:159)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
... 19 common frames omitted
I have copied Postgresql driver (postgresql-42.1.4.jar) into $CATALINA_HOME/lib directory also, that also did not help.

Failed to connect to localhost orientdb using jdbc

I'm using OrientDB 2.1.9 and has created plocal graph database called 'TimespentEvents'.
When trying to connect from Java using JDBC driver in the same machine with URL 'jdbc:orient:remote:localhost/TimespentEvents' and user/password admin/admin I encounter the following exception:
Caused by: com.orientechnologies.orient.core.exception.OConfigurationException: Error on opening database: the engine 'remote' was not found. URL was: remote:localhost/TimespentEvents. Registered engines are: [plocal, memory]
When changing the URL into 'jdbc:orient:plocal:TimespentEvents' the error turns into:
Caused by: com.orientechnologies.orient.core.exception.OStorageException: Cannot open the storage 'TimespentEvents' because it does not exist in path: localhost/TimespentEvents
Below is the jdbc driver jars I include in the classpath:
orientdb-jdbc-2.1.9.jar
orientdb-core-2.1.9.jar
Any help would be greatly appreciated.
Thanks & Regards,
Setya
Turns out I have to include 2 additional jars:
orientdb-enterprise-2.1.9.jar
orientdb-client-2.1.9.jar
Thanks & Regards,
Setya

How to integrate the WSO2 Data Services 3.0 with Oracle 10g

We use Windows Server 8 with Oracle 10g (R 10.2.0.2).
We believe that the Oracle JDBC Jar is correct, we tested some possibilities.
The problem now when we tested the connection is: "provided data source type not supported".
Anybody have any suggestion?
Thanks so much!
I believe there must be an issue with your datasource configuration defined in master-datasources.xml or any other *-datasources.xml you are using in your environment. Please double check whether the following line is defined properly in your datasource configuration. All the RDBMS databases should be configured having the definition type as "RDBMS".
<definition type="RDBMS">
A complete sample datasource configuration for your requirement is depicted below.
<datasource>
<name>testds</name>
<description>The datasource used for registry and user manager</description>
<jndiConfig>
<name>jdbc/testds</name>
</jndiConfig>
<definition type="RDBMS">
<configuration>
<url>jdbc:oracle:thin:#localhost:1521:XE</url>
<username>test</username>
<password>test</password>
<driverClassName>oracle.jdbc.OracleDriver</driverClassName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<testOnBorrow>true</testOnBorrow>
<validationQuery>SELECT 1 FROM DUAL</validationQuery>
<validationInterval>30000</validationInterval>
</configuration>
</definition>
</datasource>
Hope this helps.
Regards,
Prabath