網頁

2013年11月15日 星期五

How to get the characters right?

有時候一個小疏忽,付出的代價就是要抓蟲抓半天....
網頁最常遇到就是亂碼的問題,java要取得正確的編碼,有幾個地方要設對
1. in jsp, use pageEncoding to set the response character encoding.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
2. in html, set the charset attribute of the HTTP Content-Type header.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
3. 再來就是透過ServletRequest#setCharacterEncoding來解決server端decode的問題。且最重要的是setCharacterEncoding要在讀取request parameter前就設定,否則無效。

一時的虧手,不小心加了getParameter在網頁最上面,亂碼就出現了.........
閱讀全文...

2013年11月11日 星期一

Oracle如何檢核空字串(How to compare a VARCHAR2 variable, which is an empty value?)

上星期遇到的情況,當測試資料也建好了,就很直覺下了一個SQL語法去檢核該條件欄位是不是空的?
SQL> SELECT * FROM TXN FROM USERDATE != ''
結果卻找不到任何資料!當下覺得怎麼會這樣,明明資料才建好,不加條件就找得到資料。只好看文件找解答,最後的結果是
Oracle doesn't differentiate between empty strings and NULL, Use the IS NULL syntax to check if variable is an empty string.
閱讀全文...

2013年9月25日 星期三

Visual Source Safe Integration with IntelliJ IDEA Community Edition

本來一直都用 Eclipse 來開發 java ,想說 Google 把開發 Android 的 IDE 改成 IDEA ,那就來試試 IDEA 好不好用,興沖沖的下載安裝完成後,準備連接 VSS 下載專案程式,卻發現 IDEA 的 Version Control System 裡面根本沒有 VSS 選項,只好上 IDEA 的官網查一下,沒想到是個讓人蠻沮喪的答案...
VSS integration is available in Ultimate Edition only: http://www.jetbrains.com/idea/features/editions_comparison_matrix.html
閱讀全文...

2013年9月11日 星期三

DB2: How to find your DB2 version

要如何得知你使用的db2版本,每次問,不會被回說去找cd的包裝,就是問不到答案。
本想google一下,卻意外發現手動用command line的方式去連db,上面就有顯示了。
db2 => connect to yourdb Database Connection Information Database server = DB2/LINUX 9.7.6 SQL authorization ID = yourdb Local database alias = yourdb db2 =>
Database Server那行後面 9.7.6 就是db2 version
另也可以透過下面的SQL語法來取得db2 version,但是用此sql語法前,得先連上db,否則會出現錯誤。
db2 => select * from SYSIBM.SYSVERSIONS VERSIONNUMBER VERSION_TIMESTAMP AUTHID VERSIONBUILDLEVEL ------------- -------------------------- -------- ------------------------------ 9070600 2013-02-21-16.21.51.489830 DB2INST1 s120516 1 record(s) selected.
VERSIONNUMBER 即db2 version.

未連上db時,會得到的錯誤訊息
db2 => select * from SYSIBM.SYSVERSIONS SQL1024N A database connection does not exist. SQLSTATE=08003 db2 =>
閱讀全文...

2013年9月1日 星期日

[紙模]千陽號官方版


2in1的千陽號官方版
製作過程:







閱讀全文...

[紙模]千陽號官方版-後桅


千陽號官方版
圖紙:原11張,這次做成2in1
製作過程:





這裡很容易彎掉,需要補強

閱讀全文...

[紙模]千陽號官方版-前桅


千陽號官方版
圖紙:原11張,這次做成2in1
製作過程:



閱讀全文...

[紙模]千陽號官方版-船首


千陽號官方版
圖紙:原11張,這次做成2in1
製作過程:
感覺頭部蠻簡化的


閱讀全文...

[紙模]千陽號官方版-船身



千陽號官方版
圖紙:原11張,這次做成2in1
船身製作過程:
有些地方黏貼邊要注意一下,很容易弄反



閱讀全文...

[紙模]千陽號官方版-船尾


千陽號官方版
圖紙:原本11張,這次做 2in1
船尾製作過程:




閱讀全文...

2013年8月29日 星期四

DB2: Get current date with format YYYYMMDD

How to get current date with format YYYYMMSS in DB2??

To get the current date, time, and timestamp using SQL in DB2, reference to use below sql statment
db2 => select current date from sysibm.sysdummy1 1 ---------- 08/29/2013 1 record(s) selected. db2 => select current time from sysibm.sysdummy1 1 -------- 16:59:01 1 record(s) selected. db2 => select current timestamp from sysibm.sysdummy1 1 -------------------------- 2013-08-29-16.37.35.960388 1 record(s) selected.

How to custom date/time formatting?
The easy way to do this is use VARCHAR_FORMATscalar function
db2 => select varchar_format(current timestamp, 'YYYYMMDD') from sysibm.sysdummy1 1 ----------------------------------- 20130829 1 record(s) selected.
閱讀全文...

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
閱讀全文...

2013年5月20日 星期一

db2 encrypt/decrypt value for column(表格欄位值加解密)

全球最嚴個資法,台灣說第二,不知道有沒有其他國敢跳出來說第一,所以一堆公司開始了所謂的控管,免不的,資料庫有些敏感性資料也要加密,只好找找資料,試一下db2怎麼對表格中的欄位來進行加解密。

db2 針對不同型態,提供了不同的加解密函式,根據版本不同,有些函式還未提供,或是只供內部使用,所以只把我試出來可以用的列出來。
資料型態,主要針對varchar
使用下列函式:
  • encrypt(StringDataToEncrypt, PasswordOrPhrase, PasswordHint)
  • decrypt_dhar(EncryptedData, PasswordOrPhrase)
  • Set Encryption Password

對資料加密的演算法是一個 RC2 分組密碼(block cipher),它帶有一個 128 位的密鑰。這個128位的密鑰是通過消息摘要從密碼得來的。加密密碼與DB2認證無關,僅用於資料的加解密。
另外提供一個可選的參數 PasswordHint,這是一個字串,可以幫助用戶記憶用於對 PasswordOrPhrase 提示。

db2 db2 => connect to your_database db2 => create table xxx(cardno varchar(33) for bit data) db2 => set encryption password = 'test1234'; db2 => insert into xxx values(encrypt('1234567890123456')) db2 => select decrypt_char(cardno) from xxx db2 => quit
NOTE:
密碼至少要 6byte
新增表格時欄位長度需設定為原本欄位的最大長度+9bytes,否則在新增欄位值,會出現欄位值太長的錯誤。例如cardno原本最大長度為24,在新增table時,將其設定成33 byte

閱讀全文...

2013年5月13日 星期一

[Java]String.format 好好用

java 1.5 String.format 以前就覺得很好用,本想查查有多少 Conversion 可以用,沒想到一查 Formatter 中的各種 Conversion ,稍微試了一下,以前像 Date 處理、add leading zero、金額加上","等情況,都變得很容易處理了。
import java.util.Date; public class StringFormatT { public static void main(String[] args) { System.out.println("===== test argument index ======================================================"); System.out.println("original\t10\t20"); System.out.println("format\t\t%1$s\t%1$d\t%2$s\t%2$d"); System.out.println(String.format("result\t\t\"%1$s\"\t%1$d\t\"%2$s\"\t%2$d", 10, 20)); System.out.println("original\t10\t20\t30\t40"); System.out.println("format\t\t%1$s\t%3$d\t%4$s\t%2$d"); System.out.println(String.format("result\t\t\"%1$s\"\t%3$d\t\"%4$s\"\t%2$d", 10, 20, 30, 40)); System.out.println("================================================================================"); System.out.println("===== formatted as string ======================================================"); System.out.println("original\t\"abc\"\tnull\t(byte)1\t3.14"); System.out.println("format\t\t%s\t%S\t%s\t%S"); System.out.println(String.format("result\t\t%s\t%S\t%s\t%S", "abc", null, (byte)1, 3.14)); System.out.println("================================================================================"); System.out.println("===== formatted as boolean ====================================================="); System.out.println("original\t\"abc\"\tnull\t(byte)1\t3.14"); System.out.println("format\t\t%b\t%B\t%b\t%B"); System.out.println(String.format("result\t\t%b\t%B\t%b\t%B", "abc", null, (byte)1, 3.14)); System.out.println("================================================================================"); System.out.println("===== formatted as hex ========================================================="); System.out.println("original\t\"100\"\tnull\t100\tnew Integer(100)\t3.14"); System.out.println("format\t\t%h\t%H\t%h\t%H\t\t\t%h"); System.out.println(String.format("result\t\t%h\t%H\t%h\t%H\t\t\t%h", "100", null, 100, new Integer(100), 3.14)); System.out.println("================================================================================"); System.out.println("===== formatted as character ==================================================="); System.out.println("original\t'A'\t97\t97"); System.out.println("format\t\t%s\t%C\t%c"); System.out.println(String.format("result\t\t%s\t%C\t%c", 'A', 97, 97)); System.out.println("================================================================================"); System.out.println("===== formatted as integer ====================================================="); System.out.println("original\t100\t100\t100"); System.out.println("format\t\t%d\t%o\t%h"); System.out.println(String.format("result\t\t%d\t%o\t%h", 100, 100, 100)); System.out.println("================================================================================"); System.out.println("===== formatted as big number =================================================="); System.out.println("original\t123456789L"); System.out.println("format\t\t%1$d\t\t%1$,d"); System.out.println(String.format("result\t\t%1$d\t%1$,d", 123456789L)); System.out.println("================================================================================"); System.out.println("===== formatted as float ======================================================="); System.out.println("original\t123456789.98765"); System.out.println("format\t\t%1$.2a\t\t%1$.2e\t\t%1$.2f\t\t%1$.2g"); System.out.println(String.format("result\t\t%1$.2a\t%1$.2e\t%1$.2f\t%1$.2g", 123456789.98765)); System.out.println("================================================================================"); System.out.println("===== formatted as date ========================================================"); long currentTime = System.currentTimeMillis(); Date date = new Date(); System.out.println("original\tCurrent datetime use System.currentTimeMillis()"); System.out.println("format\t\t%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"); System.out.println(String.format("result\t\t%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", currentTime)); System.out.println("format\t\t%1$tF %1$tT"); System.out.println(String.format("result\t\t%1$tF %1$tT", currentTime)); System.out.println("original\tCurrent datetime use java.util.Date"); System.out.println("format\t\t%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"); System.out.println(String.format("result\t\t%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", date)); System.out.println("================================================================================"); System.out.println("===== What's the effect of width.precision on String? =========================="); System.out.println("original\tabcdefg"); System.out.println("format\t\t[%1$s]\t\t[%1$10s]\t[%1$10.4s]\t[%1$-10s]"); System.out.println(String.format("result\t\t[%1$s]\t[%1$10s]\t[%1$10.4s]\t[%1$-10s]", "abcdefg")); System.out.println("================================================================================"); System.out.println("===== padding easy =========================="); System.out.println("original\tadd leading zero"); System.out.println("format\t\t%012d"); System.out.println(String.format("result\t\t%012d", 123)); System.out.println("================================================================================"); System.out.println("===== test new line ============================================================"); System.out.println("original\t[%n]"); System.out.println("format\t\t%n"); System.out.println(String.format("result\t\t[%n]")); System.out.println("================================================================================"); } }

結果顯示:
===== test argument index ====================================================== original 10 20 format %1$s %1$d %2$s %2$d result "10" 10 "20" 20 original 10 20 30 40 format %1$s %3$d %4$s %2$d result "10" 30 "40" 20 ================================================================================ ===== formatted as string ====================================================== original "abc" null (byte)1 3.14 format %s %S %s %S result abc NULL 1 3.14 ================================================================================ ===== formatted as boolean ===================================================== original "abc" null (byte)1 3.14 format %b %B %b %B result true FALSE true TRUE ================================================================================ ===== formatted as hex ========================================================= original "100" null 100 new Integer(100) 3.14 format %h %H %h %H %h result bdf1 NULL 64 64 11e29ba7 ================================================================================ ===== formatted as character =================================================== original 'A' 97 97 format %s %C %c result A A a ================================================================================ ===== formatted as integer ===================================================== original 100 100 100 format %d %o %h result 100 144 64 ================================================================================ ===== formatted as big number ================================================== original 123456789L format %1$d %1$,d result 123456789 123,456,789 ================================================================================ ===== formatted as float ======================================================= original 123456789.98765 format %1$.2a %1$.2e %1$.2f %1$.2g result 0x1.d7p26 1.23e+08 123456789.99 1.2e+08 ================================================================================ ===== formatted as date ======================================================== original Current datetime use System.currentTimeMillis() format %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS result 2013-05-13 16:08:57 format %1$tF %1$tT result 2013-05-13 16:08:57 original Current datetime use java.util.Date format %1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS result 2013-05-13 16:08:57 ================================================================================ ===== What's the effect of width.precision on String? ========================== original abcdefg format [%1$s] [%1$10s] [%1$10.4s] [%1$-10s] result [abcdefg] [ abcdefg] [ abcd] [abcdefg ] ================================================================================ ===== padding easy ========================== original add leading zero format %012d result 000000000123 ================================================================================ ===== test new line ============================================================ original [%n] format %n result [ ] ================================================================================

閱讀全文...

2013年4月30日 星期二

DB2 sequence 簡單語法

剛好遇上要用db2 sequence, 將試過的語法做個備忘。

1. create
CREATE SEQUENCE XX_SEQ START 1 INCREMENT BY 1 MAXVALUE 999999 CYCLE NO CACHE
說明:
START WITH:起始值
INCREMENT BY:每次增加多少
MAXVALUE:設定最大值,不設定就設成 NO MAXVALUE
CYCLE:當到達最大值時,是否從頭開始,不循環設成NO CYCLE
CACHE:一次產生多個值於記憶體中,方便快速取用,如 CACHE 3 ,就會產生3個值於記憶體中,若不使用,則設成NO CACHE

2. alter (重新設定起始值) ALTER SEQUENCE XX_SEQ RESTART WITH 10
3. 使用 next value for seq_name 取值
SELECT NEXT VALUE FOR XX_SEQ FROM sysibm.sysdummy1
4. drop(刪除)
DROP SEQUENCE XX_SEQ RESTRICT
閱讀全文...

2013年4月26日 星期五

Customize eclipse new class template

囧,會想研究一下這東西的出發點,是因為我懶,以前新增新類別後,一些註解說明都是複製之前的類別內容,在來慢慢改,其中大部份的內容完全一模一樣,為了省下這一段工,以懶為出發點,就來研究如何客製化eclipse code template。

Step 1. 從eclipse menu 點擊 Window -> Preferences -> Java -> Code Style -> Code Templates


Step 2. 展開 Code 或 Comment ,選擇要修改的項目,在點擊 Edit 即可進行修改。


Note: 測試後發現 Comment 這部份怎麼修改都沒有反應。
最後我修改了 Code 中的兩個項目:
New java files(原始內容,其中filecomment, typecomment對應到Comment那部分,修改無效) ${filecomment} ${package_declaration} ${typecomment} ${type_declaration}

New java files(修改後,其中的log4j因為都會用到,懶到最高點,把它加進來)
${filecomment} /* * @(#)${file_name} ${date} * * Copyright (C) 2004 Your Company. * All right reserved. */ ${package_declaration} import org.apache.log4j.Logger; ${typecomment} /** * 類別說明請新增 * @author ${user} * @version 1.0 ${date} */ ${type_declaration}

Class body(原本是空的,我加了log4j和Constructor) /** for log4j */ static Logger log = Logger.getLogger(${type_name}.class.getName()); /** Constructor */ public ${type_name}() {}

經過這樣修改後,每次新增類別時,我又可以省打好多字 ^_______________^
閱讀全文...

2013年4月25日 星期四

安裝 Skype 時,錯誤訊息:先前的安裝並未完成,而且需要重新開機

msn 雖然說4/8停止服務,但一直到今天才被強制要求更新至 skype,沒想到要安裝的時候一直出現『先前的安裝並未完成,而且需要重新開機』,可是重開機,錯誤訊息還是一樣,不給裝就是不給裝。


解決方式:
以下解決方式會修改到登錄編輯程式,請自行承擔使用「登錄編輯程式」的一切風險。
1. 按一下 [開始],再按一下 [執行]/windows 7是[搜尋程式與檔案]。
2. 輸入 regedit,再按一下 [確定]。
3. 找出並按一下下列登錄機碼:
   HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
4. 找出並刪除機碼中的任何 PendingFileRenameOperations 值。
5. 提示您確認刪除時,按一下 [是]。
6. 結束 [登錄編輯程式]。
7. 重新執行 Skype 安裝程式。
閱讀全文...

2013年4月7日 星期日

[紙模]MSM-07 UC製作流程

先來張完成圖,由左至右分別為MSM-07量產型、MSM-07UC和MSM-07S專用型。

常用工具:筆刀、尺、小剪刀、膠水、夾子和牙線。


製作流程:先將圖紙上各零件切割下來,在摸索的組回各部位,很多紙模都沒說明,所以只能憑經驗去組組看,再把適合的黏起來。
腳:






手:




頭、身體主要部分:


這邊手要先裝,才能把身體的背部黏起來。


再加上腳的部分:


火箭推進裝置:


製作完成品:
MSM-07 UC


MSM-07S專用型


MSM-07量產型

閱讀全文...