SetClientProgramName In DataSource
In tomcat9
there is a setting in context.xml
:
<Resource name="jdbc/db2xx" auth="Container"
type="javax.sql.DataSource" driverClassName="com.ibm.db2.jcc.DB2Driver"
maxTotal="100" maxIdle="30"
maxWaitMillis="-1" username="xx" password="xx"
url="jdbc:db2://xxxx:xxx/dbname;" />
and in Java
is :
try {
Class.forName("com.ibm.db2.jcc.DB2SimpleDataSource");
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:/comp/env");
com.ibm.db2.jcc.DB2SimpleDataSource ds = (com.ibm.db2.jcc.DB2SimpleDataSource) envContext.lookup("jdbc/db2xx");
ds.setClientProgramName("MyApplication");
conn = ds.getConnection();
}
But I get error :
java.lang.ClassCastException: org.apache.tomcat.dbcp.dbcp2.BasicDataSource cannot be cast to com.ibm.db2.jcc.DB2SimpleDataSource
Do I have to change
org.apache.tomcat.dbcp.dbcp2.BasicDataSource
where ? The main point is
ds.setClientProgramName("MyApplication");
because I would like to see
MyApplication
in APPLICATION_NAME
when I run
SELECT APPLICATION_NAME FROM TABLE(MON_GET_CONNECTION(CAST(NULL AS BIGINT),-2))
or is there any other way ?
If I am using javax.sql.DataSource
program works, but I can not use setClientProgramName
.
In maven pom :
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>jcc</artifactId>
<version>11.5.7.0</version>
</dependency>
Answer
Client info properties support by the IBM Data Server Driver for JDBC and SQLJ.
ApplicationName
ClientAccountingInformation
ClientHostname
ClientUser
These properties mentioned at the link above can't be set with URL.
They can be set with the JDBC 4 method (use db2jcc4.jar
, not db2jcc.jar
which is JDBC 3 implementation) setClientInfo
only like below:
conn = ds.getConnection();
conn.setClientInfo("ApplicationName", "MyApplication");
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM