網頁

2013年6月26日 星期三

DB2: Insert into with select, incrementing a column for each new row by one for each insert?

工作上要用到,新增記錄到資料庫時,其中一個欄位要從SEQUENCE取值,所以試了一下SQL,順便記錄一下,免得忘了
新增一筆記錄至XXX table,其中UNIQUEID要從UNIQUE_ID_SEQ SEQUENCE取值
INSERT INTO XXX (UNIQUEID, TYPE, ID) VALUES(NEXT VALUE FOR UNIQUE_ID_SEQ,'M','004123456789001');
閱讀全文...

java.lang.NoClassDefFoundError: org/apache/oro/text/perl/Perl5Util

問題:
使用org.apache.commons.validator.GenericValidator.matchRegexp,發生下列錯誤
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.oro.text.perl.Perl5Util at org.apache.commons.validator.GenericValidator.matchRegexp(GenericValidator.java:65) at com.fesc.bot.batch.BatchJob.downloadFiles(Unknown Source) at com.fesc.bot.batch.FD903C.exec(Unknown Source) at com.fesc.bot.batch.FD903C.main(Unknown Source) Caused by: java.lang.ClassNotFoundException: org.apache.oro.text.perl.Perl5Util at java.net.URLClassLoader.findClass(URLClassLoader.java:434) at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:665) at java.lang.ClassLoader.loadClass(ClassLoader.java:644) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:358) at java.lang.ClassLoader.loadClass(ClassLoader.java:627) ... 4 more 解決:
由錯誤訊息判斷應該缺少oro project的jar
連到ORO official site,卻發現As of 2010-09-01, the ORO project is retired.

改到common-validator official site,下載最新版本的jar,重新執行程式測試,確認錯誤不會發生。

閱讀全文...

2013年6月21日 星期五

Deploying the application to websphere application server 8.5

The deployment procedures below are for using Websphere 8.5
1. In a browser, go to https://ip:port/ibm/console/login.jsp to open Administrative Console. Enter your administrative credentials to log into the system.
2. Expand the 'Application' node in the console and click the 'Install New application' link.
3. Chose the 'New Enterprise Application' link.
4. Chose the 'Local file system' radio button and click the 'Browser' button to locate the war file. click 'Next' button.
5. Chose the 'Fast Path - Prompt only when additional information is required' radio button and click 'Next' button.
6. In this section(Step 1). You can enter the installation options for your application. You can change 'Application name' and accept the default settings. click 'Next' button.
7. In this section(Step 2). you can specify target servers for clustering. you can accept the default settings here and click 'Next' button.
8. In this section(Step 3). you can specify the virtual hosts where you application will be installed to. accept the default host and click 'Next' button.
9. In this section(Step 4). you must change Context Root, Don't use '/'(already in use). if use it, when start application will get a error message like this: 'Failed to load webapp: Context root /* mapping unable to be bound'. So input you context root and click 'Next' button.
10. Review the summary of settings and click 'Finish' button.
11. When the preparation process is complete, click the 'save' link to save the application to the master configuration.
12. Expand the 'Application Type' node in the console and click the 'Websphere enterprise application' link.
13. In the Enterprise Application page, your application will appear in the list with a x symbol next to it, since has not yet been started. check the box next to application name and click the 'start' button.

You can verify you deployment by browsing to http://ip:port/

閱讀全文...

2013年6月6日 星期四

[java] Performance of StringTokenizer V.S. String.split

java 用來分割字串的方法,就我所知道有StringTokenizer和String.split。為了知道哪種效能比較好,寫了個小程式測了一下。
import java.lang.StringBuilder; import java.lang.System; import java.util.StringTokenizer; import java.util.List; import java.util.ArrayList; import java.util.Arrays; public class Test { public static void main(String[] args) { StringBuilder sb = new StringBuilder(); for (int i=1000; i<1100; i++) { sb.append(i).append(" "); } String str = sb.toString(); int runs = 100000; for (int i = 0; i < 5; i++) { { long start = System.nanoTime(); for (int r = 0; r < runs; r++) { StringTokenizer st = new StringTokenizer(str); List list = new ArrayList(); while (st.hasMoreTokens()) { list.add(st.nextToken()); } } long time = System.nanoTime() - start; System.out.printf("StringTokenizer took an average of %.1f us%n", time / runs / 1000.0); } { long start = System.nanoTime(); for (int r = 0; r < runs; r++) { List list = Arrays.asList(str.split(" ")); } long time = System.nanoTime() - start; System.out.printf("String.split took an average of %.1f us%n", time / runs / 1000.0); } } } }
結果顯示:
StringTokenizer took an average of 12.7 us String.split took an average of 9.8 us StringTokenizer took an average of 12.6 us String.split took an average of 9.4 us StringTokenizer took an average of 12.6 us String.split took an average of 9.4 us StringTokenizer took an average of 13.2 us String.split took an average of 9.4 us StringTokenizer took an average of 12.5 us String.split took an average of 9.5 us
看來String.split表現得比較好
閱讀全文...

[java] String.split()用法

在java,可以使用String.split(delimiter),將字串分割成數個token,得到一個回傳的String array。
例如:
String str = "aaa:bbb:ccc:ddd"; String[] tokens = str.split(":"); for (String token:tokens) { System.out.println(token); }
結果顯示:
aaa bbb ccc ddd
如果字串中有多個分隔符號時,就須加上"|"。
String str = "aaa:bbb-ccc_ddd"; String[] tokens = str.split(":|-|_"); for (String token:tokens) { System.out.println(token); }
結果顯示:
aaa bbb ccc ddd
當delimiter用到特殊字元時,如".", "|", "$",此時要在特殊字元前面加上"\\",才會得到正確的結果。
String str = "aaa-bbb-ccc.ddd"; String[] tokens = str.split("-|\\."); for (String token:tokens) { System.out.println(token); }
結果顯示:
aaa bbb ccc ddd
閱讀全文...