I used to use TOAD to monitor the connection to Oracle, but when I moving to DB2 world, I am struggling to find out a similar tool to look at what kind connections/activities happen on the Database. One of my collegue suggested DB2Mon, I set off and decide to give it a try, here I record what I need to do:
1. Start IBM DB2 Configuration Assistant, right click, Add Database Using Wizard, Manually configure a connection to a database; setup your database connection; Test your connection by right click the newly created connection->TestConnection->CLI
2. Start your DB2Mon, you should see your newly created Database connection, select it and input your user/password.
Showing posts with label IBM. Show all posts
Showing posts with label IBM. Show all posts
Thursday, December 22, 2011
Thursday, December 8, 2011
How to get a JDBC connection in EJB 3 running on WebSphere
There are several ways to get a JDBC connection in EJB3 running on WebSphere:
1. JNDI lookup
2. @Resource Injection
2.1 In ibm-ejb-jar-bnd.xml
<session name="OrderRepositoryBean">
<resource-ref name="DFSAdabasDataSource" binding-name="jdbc/DFS_ADABAS" />
</session>
2.2 In OrderRespositoryBean
@Resource(name = "DFSAdabasDataSource")
private DataSource ds;
3. NOT WORK!!! @Resource Injection by using mappedName, assuming the JNDI name is : jdbc/DFS_ADABAS
// In OrderRepositoryBean
@Resource(mappedName = "jdbc/DFS_ADABAS")
private DataSource ds;
4. Using OpenJPAEntityManager
@PersistenceContext(unitName = "CACSAMP")
private EntityManager emDFS;
......
(Connection) ((OpenJPAEntityManager) emDFS.getDelegate()).getConnection();
1. JNDI lookup
2. @Resource Injection
2.1 In ibm-ejb-jar-bnd.xml
<session name="OrderRepositoryBean">
<resource-ref name="DFSAdabasDataSource" binding-name="jdbc/DFS_ADABAS" />
</session>
2.2 In OrderRespositoryBean
@Resource(name = "DFSAdabasDataSource")
private DataSource ds;
3. NOT WORK!!! @Resource Injection by using mappedName, assuming the JNDI name is : jdbc/DFS_ADABAS
// In OrderRepositoryBean
@Resource(mappedName = "jdbc/DFS_ADABAS")
private DataSource ds;
4. Using OpenJPAEntityManager
@PersistenceContext(unitName = "CACSAMP")
private EntityManager emDFS;
......
(Connection) ((OpenJPAEntityManager) emDFS.getDelegate()).getConnection();
Wednesday, December 7, 2011
How to currentSchema for DB2 DataSource in WebSphere
Without setting the currentSchema for DB2, you need to fully qualified the DB object (table, view etc) name.
According IBM documentation, currentSchema means "This allows the end user or application to name SQL objects without having to qualify them by schema name."
How to setup the crrentSchema for DB2 DataSource in Websphere?
Resources->JDBC->Click your Data Source name->Customer properties->currentSchema.
Restart your Websphere to make it take effective.
BTW: The DataSource currentSchema setting could be co-exist with the openjpa.jdbc.Schema setting in persistent.xml without intereference with each other.
According IBM documentation, currentSchema means "This allows the end user or application to name SQL objects without having to qualify them by schema name."
How to setup the crrentSchema for DB2 DataSource in Websphere?
Resources->JDBC->Click your Data Source name->Customer properties->currentSchema.
Restart your Websphere to make it take effective.
BTW: The DataSource currentSchema setting could be co-exist with the openjpa.jdbc.Schema setting in persistent.xml without intereference with each other.
Friday, November 18, 2011
How to get the Database connection URL from OpenJPA EJB
Normally you would like to have a quick and easy way to tell which DB your application is connect to. To get this kind of you information in an OpenJPA/EJB3 stack, you may be able to do the following:
public String getDataBaseURL() {
final Connection conn = (Connection) ((OpenJPAEntityManager) em.getDelegate()).getConnection();
String url;
try {
url = conn.getMetaData().getURL();
} catch (final SQLException e) {
url = "Failed to get the DB URL";
}
return url;
}
public String getDataBaseURL() {
final Connection conn = (Connection) ((OpenJPAEntityManager) em.getDelegate()).getConnection();
String url;
try {
url = conn.getMetaData().getURL();
} catch (final SQLException e) {
url = "Failed to get the DB URL";
}
return url;
}
Thursday, July 7, 2011
Decoding IBM DB2 error message
Ever get an IBM DB2 error message like "SQL0407N Assignment of a NULL value to a NOT NULL column TBSPACEID=n1, TABLEID=n2, COLNO=n3 is not allowed. What actually does "TBSPACEID=n1, TABLEID=n2, COLNO=n3" mean? Don't ask me, you should ask IBM DB2, but how?
SELECT C.TABSCHEMA, C.TABNAME,
C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = n1
AND T.TABLEID = n2
AND C.COLNO = n3
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME
SELECT C.TABSCHEMA, C.TABNAME,
C.COLNAME
FROM SYSCAT.TABLES AS T,
SYSCAT.COLUMNS AS C
WHERE T.TBSPACEID = n1
AND T.TABLEID = n2
AND C.COLNO = n3
AND C.TABSCHEMA = T.TABSCHEMA
AND C.TABNAME = T.TABNAME
Subscribe to:
Posts (Atom)