2011年8月6日 星期六

Ubuntu下安裝DB2 Express-C

# ./db2setup
ERROR:
   The required library file libaio.so.1 is not found on the system.
   Check the following web site for the up-to-date system requirements
   of IBM DB2 9.7
   http://www.ibm.com/software/data/db2/udb/sysreqs.html
   http://www.software.ibm.com/data/db2/linux/validate
  Aborting the current installation ...
  Run installation with the option "-f sysreq" parameter to force the installation.






需先安裝:
sudo apt-get install libaio-dev

ref:
http://packages.ubuntu.com/zh-tw/natty/libaio-dev
This library enables userspace to use Linux kernel asynchronous I/O system calls, important for the performance of databases and other advanced applications.


p.s.聽說安裝Oracle資料庫前也需安裝

2011年7月14日 星期四

valueOf()、Wrapper Constructor 、 xxxValue()及 parseXxx()的用法及不同

(1)將String(或基本型別Primitive Type)轉成Wrapper Object
     ==>使用Wrapper Constructor

(2)將String轉成Wrapper Object
     ==>使用valueOf()
    p.s. valueOf()提供指定基數表示法

(3)將String轉成基本型別Primitive Type
    ==>使用parseXxx()

(4)將Wrapper Object轉成基本型別Primitive Type
    ==>xxxValue()

p.s.1: xxx的都是轉成Primitive Type
p.s.2:valueOf()、 xxxValue()及 parseXxx()都是外覆類別提供的Method
p.s.3:Boolean物件的valueOf()不會拋出NumberFormatException (NFE)
p.s.4: Boolean a = new Boolean("Test");
          System.out.println(a);
          結果是:false,因為除了傳入True(不分大小寫)外都是false

ref 1:NumberFormatException (NFE)
ref 2:toXxxString() (二進位、十六進位、八進位)

2011年3月13日 星期日

eclipse連jndi

使用Helios Service Release 2 + WTP,tomcat 6
問題點在不透過eclipse(直接用tomcat)連jndi都ok
一透過eclipse連jndi就出錯,錯誤訊息如下:
Cannot create JDBC driver of class '' for connect URL 'null'
因為原本jndi我訂在tomcat的server.xml
但eclipse複製server.xml到eclipse的workspace時,不知道為啥都會把jdbc連線資訊去掉
後來改修改tomcat的context.xml,eclipse複製context.xml到workspace時才不會亂刪
才連線成功
如果不修改tomcat的context.xml,在專案的WebContent/META-INF建立一份
context.xml也可
如果tomcat版本是4.1以上
基本上建議JNDI訂在META-INF/context.xml
包含path及docBase
                                                                              
                                                                              
ref:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
http://wiki.eclipse.org/WTP_Tomcat_FAQ

Shell Script連MySQL

somevar=`echo "select A from B" | mysql -u $USER -p$PWD -D $DB `

db2上得到日期

db2 => select current date from sysibm.sysdummy1

1
----------
2011-03-13

    已選取 1 個記錄。


db2 => SELECT CURRENT TIMESTAMP FROM SYSIBM.SYSDUMMY1

1
--------------------------
2011-03-13-18.00.25.177000


db2 => select date ( days( current date) -1 ) yesterday_date from sysibm.sysdumm
y1

YESTERDAY_DATE
--------------
2011-03-12

    已選取 1 個記錄。




db2 => select year(current date) 年,month(current date) 月,day(current date) 日
from sysibm.sysdummy1

年          月          日
----------- ----------- -----------
       2011           3          13

    已選取 1 個記錄。


db2 => select char( year(current date) ) from sysibm.sysdummy1

1
-----------
2011


db2 => select char( year(current date) ) ,char(month(current date)),char(day(cur
rent date)) from sysibm.sysdummy1

1           2           3
----------- ----------- -----------
2011        3           13

    已選取 1 個記錄。


db2 => select concat( concat(trim(char(year(current date))),trim(char(month(curr
ent date))) ),trim(char(day(current date)))) from sysibm.sysdummy1

1
---------------------------------
2011313

    已選取 1 個記錄。


db2 => select substr(char(year(current date)),1,4)|| case when month(current dat
e) <= 9 then '0'||substr(char(month(current date)),1,1) else substr(char(month(c
urrent date)),1,2) end || case when day(current date) <= 9  then '0'||substr(cha
r(day(current date)),1,1) else substr(char(day(current date)),1,2) end from sysi
bm.sysdummy1

1
--------
20110313

    已選取 1 個記錄。


REF:
http://www.ibm.com/developerworks/data/library/techarticle/0211yip/0211yip3.html
http://www.tek-tips.com/viewthread.cfm?qid=535886&page=85

2010年9月22日 星期三

(MySQL)group by



加上having
找出銷售額大於300000店鋪(sid)