2010年11月29日 星期一

Python 2.7 Connect MySQL

依序下載程式安裝
1. Python 2.7
2. SetupTools 2.7
3. MySQL-python 1.2.3 for windows and python 2.7

測試 Connect MySQL 是否可運作
1. 開啟 Python 2.7 IDLE
2. 編輯測試程式
>>> import MySQLdb
>>> db = MySQLdb.connect(host="localhost", user="xxxx", passwd="xxxx", db="xxxx")
>>> cursor = db.cursor()
>>> cursor.execute("select * from system_user")
2L
>>> result = cursor.fetchall()
>>> for record in result :
        print record[0]


USERE00000000000000000001
USERE00000000000000000002
>>>

2010年10月25日 星期一

Android XmlRpc Remote Service Problem

測試 Android 系統使用 XmlRpc 呼叫遠端的服務時遇到二個問題

1. java.net.SocketExeption: Permission denied
2. localhost connection refused

第一個問題是因為在Android Application中沒有開啟 Internet 使用權限
解決方法是在 Manifest檔內加上
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
就可以正常運作

第二個問題是因為在 Android Simulator 把自己作為 localhost 了,
所以如果在程式中寫 localhost 要連至本機的 Server 將會出現此問題
如果要連至本機的 Server 就必需將 IP 設為 10.0.2.2


參考網站
java.net.SocketException:Permission denied
localhost connection refused

2010年10月12日 星期二

JDBC for Sqlite DB

1. 下載必要的Jar檔
     sqlite-jdbc-3.7.2 可至 Xerial 下載使用

2. 建立好Sqlite DB後, 將Sqlite的DB檔放至某處 (ex. C:\test.db)

3. 用以下的程式碼測試


String url = "jdbc:sqlite://C:\\test.db";
try {
  Class.forName("org.sqlite.JDBC");
  Connection con = DriverManager.getConnection(url);
  String query = "select * from test_T";
  Statement stmt = con.createStatement();
  con = DriverManager.getConnection(url);
  ResultSet rs = stmt.executeQuery(query);
  while (rs.next()) {
    out.print(rs.getString("Id")+"&nbsp;"+rs.getString("Password")+"<br/>");
  }
  rs.close();
  stmt.close();
} catch (Exception e) {
  e.printStackTrace();
  out.print(e.getMessage());
}


p.s. 記得 import 相關的 class 檔
ex.
import java.sql.Connection;
import java.sql.*;
import org.sqlite.JDBC;

以上是一個簡易的Sqlite連線

2010年9月26日 星期日

Mac OS Server 服務的相關 Port

Remote Login (SSH) - 22
Screen Sharing Service (VNC) - 5900
AddressBook Service - 8800, 8843
iChat Service - 5222, 5223, 5060, 5269, 7777
Mail Service (SMTP, IMAP, POP) - 25, 110, 143, 587, 993, 995
Web Service - 80, 443
VPN Service (L2TP) - 500, 1701, 4500
VPN Service (PPTP) - 1723
File Sharing Service (AFP, SMB) - 548, 139

參考URL
http://support.apple.com/kb/TS2963

2010年9月16日 星期四

Setting Debugging PHP with Xdebug

1. download xdebug 

2. copy xdebug's dll to php\ext\ (ex. C:\Program Files\PHP\ext)

3. modify php.ini add xdebug define (if xdebug's dll name is php_xdebug-2.0.5-5.2.dll)
    zend_extension_ts="C:\Program Files\PHP\ext\php_xdebug-2.0.5-5.2.dll"
    xdebug.remote_enable=1 
    xdebug.remote_handler=dbgp 
    xdebug.remote_host=127.0.0.1 
    xdebug.remote_port=9000 
    xdebug.remote_mode=req 
    xdebug.idekey=default 
    xdebug.remote_log="c:\tmp\xdebug\xdebug.log" 
    xdebug.show_exception_trace=0 
    xdebug.show_local_vars=9 
    xdebug.show_mem_delta=0 
    xdebug.trace_format=0 
    xdebug.profiler_enable  = 1 
    xdebug.profiler_output_dir ="c:\tmp\xdebug"

4. Make sure you create the folder c:\tmp\xdebug\

5. restart apache

6. look phpinfo()
  















Reference URL : http://www.webcheatsheet.com/php/debug_php_with_xdebug.php

2010年9月4日 星期六

設定Input只能輸入數值


在Script Tag之中加入限制的方法

<Script>

...

$(function() 
{
$('#InputID').bind('keypress', filterWithOutNumber)
});



//限制只能輸入數值的方法
function filterWithOutNumber(e) 
{
if(e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
return false;
else
return true;
}

...

</Script>

<body>
<Input type="text" id="InputID"></Input>
</body>


2010年8月12日 星期四

How to Delete a Windows Service

Command 語法如下
    sc delete [ServiceName]

Ex.
    sc delete "GlassfishService"