Thursday, December 27, 2012

[ORACLE] Get size in BYTE of a column

LENGTHB(COLUMN_NAME)

謝謝有為的中年人<(_ _)>
ref: KB-在Oracle中直接取得中文字串長度

Tuesday, December 25, 2012

Change File Permission via ftpd

方案一,上傳檔案才chmod修改檔案權限
In Windows command line:
ftp> chmod
Invalid command.
Do it by "quote" command:
ftp> quote
Command line to send site chmod 666 filename.txt
200 CHMOD command successful.
缺點:
FTP裡下chmod指令無法使用萬用字元(*, wildcard),也無法使用 -R flag。
好不容易知道怎麼透過FTP下chmod了... 不實用

Using Apache Commons Net 3.2 API in java:
   1:  //using public int sendCommand(String command, String args)
   2:  //實在不知道那些字要放在command, 哪些字要放在args, try了好幾次
   3:  //TEST#1:
   4:  FTPClient.sendCommand("quote", "site chmod 666 *");
   5:  //command result=500 'QUOTE site chmod 666 *': command not understood.
   6:   
   7:  //TEST#2:
   8:  FTPClient.sendCommand("quote site chmod", "666 *");
   9:  //command result=500 'QUOTE site chmod 666 *': command not understood.
.....試了N百個組合都不認得, go die
還有error message回傳的指令都寫大寫也很奇怪.. unix大小寫有差啊,我要小寫!!

最後讀了public int sendCommand(int command, String args)方法才知道他根本就沒提供quote這個指令OTZ||| 從FTPCommand看起來,"SITE"是最有可能會動的指令:
   1:  //TEST#3:
   2:  FTPClient.sendCommand("site", "chmod 666 *");
   3:  //command result=550 *: A file or directory in the path name does not exist.
........ 透過程式來做也一樣,*不能用,再度遭受打擊OTZ|||
   1:  //TEST#4:
   2:  FTPClient.sendCommand("site", "chmod 666 filename.txt");
   3:  //command result=200 CHMOD command successful.
一次只能改一個檔案也太讓人不爽了。所以先上傳檔案才修改檔案權限的方案透過FTP不work。

方案二,登入FTP後先下umask指令來控制檔案權限
In Windows command line:
ftp> quote
Command line to send site umask 000
200 UMASK set to 000 (was 007)

Using Apache Commons Net 3.2 API in java:
   1:  //TEST#5:
   2:  FTPClient.sendCommand("site", "umask 002");
   3:  //command result=200 UMASK set to 002 (was 007)
特別提醒透過下umask方法目前測起來只對FTP有用,SFTP應該無效
又是另一項作業..

Ref:

  1. [API] FTP.sendCommand(String, String)
  2. [API] FTPCommand class
Wednesday, January 04, 2012

Using Editable JComboBox with KeyEvent

//The following code wont’t work
JComboBox jcb1 = new JComboBox();
jcb1.setEditable(true);
jcb1.addKeyListener(aKeyEventObject);

//Correct: KeyEvent should be added to JComboBox.getEditor().getEditorComponent()
JComboBox jcb2 = new JComboBox();
jcb2.setEditable(true);
jcb2.getEditor().getEditorComponent().addListerer(aKeyEventObject);

Calling to JComboBox.getEditor().getEditorComponent() will return a JTextField that is used for editing the comboBox’s text.

And if at the same moment you want to get the filling text:

//The following code won’t work(return null)
String s = jcb2.getSelectedItem().toString();

//Correct:
String s = ((JTextComponent)jcb.getEditor().getEditorComponent()).getText();

Tags