Hope this helps you.
Sunday, June 2, 2013
Remote Desktop Black Screen?!
Log to your PC at work and get a black screen, what should you do? No need to panic, you can try CTRL-ALT-END, which is the way you send CTRL-ALT-DEL to your remote desktop.
Thursday, January 26, 2012
Test DB2 JDBC Data source failed in WebSphere 7 cluster
As far as how to create a new DB2 datasource in WebSphere 7 is pretty straightforward, it contains two steps:
1. Create a new JAAS J2C data entry to hold your username and password.
2. Create a new DataSource by using the newly created JAAS J2C data entry.
That's all you need to do. But where may be a catch when you try to do it in a cluster environment, you may run into the following exepction when you try to test your newly created Data source:
java.lang.Exception: java.sql.SQLException: null userid not supported
My solution is to restart the nodeagents on the custer nodes.
1. Create a new JAAS J2C data entry to hold your username and password.
2. Create a new DataSource by using the newly created JAAS J2C data entry.
That's all you need to do. But where may be a catch when you try to do it in a cluster environment, you may run into the following exepction when you try to test your newly created Data source:
java.lang.Exception: java.sql.SQLException: null userid not supported
My solution is to restart the nodeagents on the custer nodes.
Thursday, December 22, 2011
How to setup and use DB2Mon
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.
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.
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
Configure IBM InfoSphere Classic JDBC Driver datasource in WebSphere
To setup the InfoSphere Classic JDBC Data source in WebSphere, you could follow the following steps:
1. Create new JDBC Provider
1.1 Resources->JDBC->JDBC providers->new
1.2 Database type: User-defined; Implementation class name: com.cac.jdbc.ConnectionPoolDataSource; Name: IBM InfoSphere Classic JDBC
1.3 Class path: ${User-defined_JDBC_DRIVER_PATH}/DataFederationServer/cacjdbc21.jar
1.4 Review summary->Finish->save
2. Create Java 2 Connector authentication data entry
2.1 Security->Global security; Under Authentication cache settings, click Java Authentication And Authorization Service->J2C authnetication data; new
2.2 Alias:; UserID: ; Password: ; Apply-> save
3. Create new Data Source
3.1 Resources->JDBC->Data sources; new
3.2 Data source name: DFS_XXXX; JNDI name: jdbc/DFS_ADABAS
3.3 Select the JDBC provider created in step 1.
3.4 Data store helper class name: com.ibm.websphere.rsadapter.GenericDataStoreHelper; Uncheck used for CMP check box.
3.5 Component-managed authentication alias: the one you created in step 2.
3.6 Review summary->Finish->save
3.7 setup the Custom properties for the newly create Data source by click on the Data source name -> Customer properties
3.7.1 URL: your Data Federation Server JDBC URL;
3.7.2 webSphereDefaultIsolationLevel: 1 (READ_UNCOMMITED); very tricky, I can only make it work by setting to 1. It turns out the backend (ADABAS) is set to support READ_UNCOMMITED.
3.8 If you run into "JDBC hung when try to close connection" in your application, try to turn off the statement cache; Search IBM fix pack change list for similar problem for Oracle, and Sybase JDBC connection.
You almost done, just restart your web sphere server and start to use the JDBC Data source.
1. Create new JDBC Provider
1.1 Resources->JDBC->JDBC providers->new
1.2 Database type: User-defined; Implementation class name: com.cac.jdbc.ConnectionPoolDataSource; Name: IBM InfoSphere Classic JDBC
1.3 Class path: ${User-defined_JDBC_DRIVER_PATH}/DataFederationServer/cacjdbc21.jar
1.4 Review summary->Finish->save
2. Create Java 2 Connector authentication data entry
2.1 Security->Global security; Under Authentication cache settings, click Java Authentication And Authorization Service->J2C authnetication data; new
2.2 Alias:
3. Create new Data Source
3.1 Resources->JDBC->Data sources; new
3.2 Data source name: DFS_XXXX; JNDI name: jdbc/DFS_ADABAS
3.3 Select the JDBC provider created in step 1.
3.4 Data store helper class name: com.ibm.websphere.rsadapter.GenericDataStoreHelper; Uncheck used for CMP check box.
3.5 Component-managed authentication alias: the one you created in step 2.
3.6 Review summary->Finish->save
3.7.1 URL: your Data Federation Server JDBC URL;
3.7.2
You almost done, just restart your web sphere server and start to use the JDBC Data source.
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;
}
Tuesday, September 13, 2011
Windows firewall blocks access to Apache Tomcat service from remote computer
Today, my colleague installed Tomcat as windows service on a Windows 7 box, strangely he could access via http://127.0.0.1:8080 and http://ipofserver:8080, but he could not access http://ipofserver:8080 from a remote computer. After some digging, it turns out to be the Windows 7 firewall blocked the remote access traffic. The solution of the problem is simple: just manually start the tomcat7.exe, Windows 7 will show the firewall warning dialog, just allow access.;-)
Tuesday, August 30, 2011
JNI Refreshment
Today one of my colleague asked me some questions on JNI implementation. The knowledge seems fading away from me. To avoid it happens again, I recorded the basic steps:
- Delare your native methods in a normal Java class, for example, HelloJNI.java.
- javac the java file(HelloJNI.java).
- javah -jni HelloJNI to generate the .h file(s).
- Write your native code, using the .h file generated in step 3; copy the function prototye from the .h file into your .c file.
- compile by using Visual Studio 2005 command shell(cl command).
- Modify your java class to load the library; recompile it; ready to run it!!!
- http://java.sun.com/docs/books/jni/html/jniTOC.html
- http://patriot.net/~tvalesky/jninative.html
- http://java.sun.com/developer/onlineTraining/Programming/JDCBook/jniexamp.html#comp
- command to compile your c file: c:\test\jnitest>cl /I"C:\Program Files (x86)\Java\jdk1.6.0_24\include" /I"C:\Program Files (x86)\Java\jdk1.6.0_24\include\win32" -LD HelloJNI.c -Felibnative.dll
- JNI in package
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
Wednesday, January 5, 2011
Install Oracle Developer Suite 10g on Windows 7 (64bit)
Recently, I got a task to install Oracle Developer Suite on Windows 7(64bit), but there seems lots of hassles to achieve this goal. There is a thread on Oracle forum on that topic. Here I log what I did to get it installed on my Windows 7(64bit) with 8G RAM.
- extract the setup files (version 101202) downloaded from otn.
- right click the install\setup.exe property, set compatibility to Windows XP SP2
- edit the virtual memory size to custom size from 1024m to 8000m, restart it
- run the install\setup.exe
Saturday, December 4, 2010
Oracle 11g alert log location
Oracle alert log contains much useful information about your Oracle database, but do you know where is it located and how could you find it out?
Connect to the database with SQL*Plus or another query tool, such as SQL Developer.
Query the
V$DIAG_INFOview as shown in "Viewing ADR Locations with the V$DIAG_INFO View".To view the text-only alert log, without the XML tags, complete these steps:
In the
V$DIAG_INFOquery results, note the path that corresponds to theDiagTraceentry, and change directory to that path.Open file alert_SID.log with a text editor.
To view the XML-formatted alert log, complete these steps:
In the
V$DIAG_INFOquery results, note the path that corresponds to theDiagAlertentry, and change directory to that path.Open the file log.xml with a text editor.
Monday, September 6, 2010
How to use Android Market on Android Emulator 2.2
- Start SDK Setup.exe and create an AVD - android-2.2
- Copy system.img coming with the SDK platform to the newly created AVD.
copy c:\labs\android-sdk-windows\platforms\android-8\images\system.img .
- Start the emulator by using command line:
- Pull build.prop from the emulator for editing:
- Comment out ro.config.nocheckin=yes line from the build.prop file just pulled out from the emulator.
- Push back the updated build.prop file to the emuloator
C:\labs\android-sdk-windows\tools>adb.exe push build.prop /system/build.prop
- Grab the MoDaCo Custom ROM for Nexus
- Push GoogleServicesFramework.apk, Vending.apk to emulotor, and remove SdkSetup.apk
C:\labs\android-sdk-windows\tools>adb.exe push c:\labs\r21-update-nexusone-modacocustomcustomrom-withadditions-chinese-signed\system\app\Vending.apk /
system/app
C:\labs\android-sdk-windows\tools>adb shell rm /system/app/SdkSetup.apk
- Stop the emulator and delete the files: userdata-qemu.img, userdata.img, cache.img
- start the emulator by using command line again, you should get the Android Market in your emulator.
Sunday, April 25, 2010
SAP IDES 4.7
The best place to start learning SAP is to try out the SAP IDES, International Demonstration and Education System. Here are some of the default settings for IDES 4.7 after installation:
- Client ID: 800
- Login user/pwd: sap*/06071992
- Login user/pwd: ddic/19920706
Saturday, April 10, 2010
How to remote debug Tomcat server code?
Either you are a developer of Tomcat or you would like to see how the Tomcat works in a live mode, you may want to set a few break points in the Tomcat codes and to see the code in the live run. How could you set up remote debug for tomcat? Thanks for the JPDA(Java Platform Debug Architecutre) we can easily achieve this goal.
- Start tomcat server with remote debug enabled with JVM parameters: -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y and make sure you setting suspend=y to let the tomcat server suspend and wait for debugger to attach to it.
- Start your debugger, I am using Intellij Remote Debug, and here is the settings: Host: localhost Port: 8000
Sunday, April 4, 2010
Install lxml on Cygwin
To install lxml on Cygwin you need jump through a few hoops, to save who wants to get it done smoothly, I write down the necessary steps:
- Make sure install the following package for cygwin by using Cygwin setup libxml2, libxml2-devel, libxslt, libxslt-devel, python-libxml2, python-libxslt
- If you got lots of errors about debug format:
- try to add -gdwarf-2 to CFLAGS
- export CFLAGS="-gdwarf-2"
Using pip, virtualenv, and virtualenvwrapper in Cygwin
I have been using pip, virtualenv, and virtualenvwrapper in Cygwin for long time, it is pretty handy to isolate my development environment for each python projects I am working on. But I still need to think about what need to be done to setup all the pip, virtualenv, and virtualenvwrapper on Cygwin. To save my time and help anybody would like to setup the stuff on Cygwin, I recorded the process as following:
- Use Cygwin setup to install Python for Cygwin.
- Install easy_install in your Cygwin: download and run ez_setup.py in Cygwin.
- Install pip by using easy_install: eazy_install pip.
- pip install virtualenv
- pip install virtualenvwrapper
- add the following lines into your ~/.bashrc
- export WORKON_HOME=/cygdrive/c/labs/virtualenvs
source /usr/bin/virtualenvwrapper_bashrc
Labels:
cygwin,
pip,
python,
virtualenv,
virtualenvwrapper
Monday, March 29, 2010
Using HQL Console for JPA facet in Intellij
You got a complicated HQL or JPAQL in your code that has some problems, you need to verify what exactly the query is doing, how should you go ahead to test run it in your database? One option is that you can read the HQL or JPAQL and manually translate it to SQL statement and run the sql statement in your Database, however, this method is error prone and tedious. Another option is use the HQL Console came with Intellij, I found this method is easy and more accurate comparing to the previous options. Here is how I did it:
- Create a DataSource in Intellij, let's name it datasource_1
- Go to the Project->View:J2EE structure->right click the module your pojos are located in, edit the JPA facet properties to set datasource_1 maps to the desired Persistent Unit, and set the default JPA provider to: Hibernate.
- Project->View:J2EE structure->right click the Persistent Unit, you should be able to start HQL Console.
- You can paste your HQL or JPAQL in the HQL Console and try it out, or you can generate SQL for it and run the SQL in your DB.
Wednesday, December 9, 2009
Unable to access jarfile on Cygwin
Today I ran into a strange problem on Cygwin: I give the full path to the jar file for the java command, but strangely, the java runtime shows me the error message: Unable to access jarfile /cygdrive/c/pathtojar/.yuicompressor.jar. What is going on? did I have a typo? No. Then Why? After scratch my head enough, I figure out that the java in Cygwin does not like Unix format path to specify the jar file. You can use cygpath to do the trick to convert the Unix format path to mixed(-m) or windows format(-w) path, the java command will happily take it and use the jar file. Here are the two commands that works for me:
- java -jar `cygpath -m /cygdrive/c/pathtojar/.yuicompressor.jar`
- java -jar `cygpath -w /cygdrive/c/pathtojar/.yuicompressor.jar`
pip install python packages makes it easy
pip is easy_install replacement, and it is easy to use. Here are some features I recently used:
- To install something from Python Package Index, for example, Django 1.1, you just issue: pip install django, it will download it and install it.
- To see what Python Packages were installed by pip, you can use command: pip freeze, of course, you can redirect the output to a file and pass around.
- To uninstall a Python Package, for example, Django 1.1 installed in step 1, the command is: pip uninstall django.
- To install some Python Package you may run into error: No distributions at all found for xxxxx, you can supply the package file url to the pip install command, for example, if you want to install Django 0.96.5, here is the command: pip install http://www.djangoproject.com/download/0.96.5/tarball/, this one is pretty cool, if you can find the package gz file, then you can install it by using pip.
Subscribe to:
Posts (Atom)