由於Sybase資料庫保密及系統只能使用文字模式的問題,造成我只能使用command line的方式來查詢資料庫,找半天資料都大多都是要安裝Sybase ASE或iSQL,但又似乎無法只安裝iSQL,雖然有免費的開發版本,但連下載Sybase的軟體的link都要找半天,找到了還要註冊一堆資料,雖然弄好了,但安裝設定一堆有的沒的,我放棄了,最後到
Open Source SQL Clients in Java找到了
HenPlus。
HenPlus下載連結:
http://sourceforge.net/projects/henplus/files/
下載完後,要先用ANT做compiler,要先安裝JDK,下載ANT(
Download),ANT下載後直接在家目錄下解壓縮。設定PATH參數
$export PATH=$PATH:~/(剛才解壓縮的ant目錄)/bin
再來將下載的HenPlus解壓縮
$tar jxvf henplus-0.9.8.tar.gz
$cd henplus-0.9.8
$ant jar
在這邊要注意的是,若是用root安裝,可以用ant install,但若是個人使用而已,則用ant jar。
最後compiler好後,就可以用底下的執令來
$cd bin
$./henplus
再來是加入Driver,先列出目前預設的。
Hen*Plus> list-drivers
------------+---------------------------------+---------+-----------------------------------------+
for | driver class | Version | sample url |
------------+---------------------------------+---------+-----------------------------------------+
Adabas | de.sag.jdbc.adabasd.ADriver | [NULL] | jdbc:adabasd://localhost:7200/work |
DB2 | COM.ibm.db2.jdbc.net.DB2Driver | [NULL] | jdbc:db2://localhost:6789/foobar |
* MySQL | org.gjt.mm.mysql.Driver | 5.0 | jdbc:mysql://localhost/foobar |
Oracle | oracle.jdbc.driver.OracleDriver | [NULL] | jdbc:oracle:thin:@localhost:1521:ORCL |
SAP-DB | com.sap.dbtech.jdbc.DriverSapDB | [NULL] | jdbc:sapdb://localhost/foobar |
------------+---------------------------------+---------+-----------------------------------------+
我主要是要sybase,要先找到jconn3(
jconn3.jar下載),我是放在henplus-0.9.8/lib底下,然後打底下的命令
Hen*Plus> register sybase com.sybase.jdbc3.jdbc.SybDriver jdbc:sybase:Tds:localhost:xxxx/db
Hen*Plus> list-drivers
loaded drivers are marked with '*' (otherwise not found in CLASSPATH)
------------+---------------------------------+---------+-----------------------------------------+
for | driver class | Version | sample url |
------------+---------------------------------+---------+-----------------------------------------+
Adabas | de.sag.jdbc.adabasd.ADriver | [NULL] | jdbc:adabasd://localhost:7200/work |
DB2 | COM.ibm.db2.jdbc.net.DB2Driver | [NULL] | jdbc:db2://localhost:6789/foobar |
* MySQL | org.gjt.mm.mysql.Driver | 5.0 | jdbc:mysql://localhost/foobar |
Oracle | oracle.jdbc.driver.OracleDriver | [NULL] | jdbc:oracle:thin:@localhost:1521:ORCL |
SAP-DB | com.sap.dbtech.jdbc.DriverSapDB | [NULL] | jdbc:sapdb://localhost/foobar |
* sybase | com.sybase.jdbc3.jdbc.SybDriver | 6.0 | jdbc:sybase:Tds:localhost:xxxx/db |
------------+---------------------------------+---------+-----------------------------------------+
再來連結資料庫,用connect指令
Hen*Plus> connect jdbc:sybase:Tds:localhost:xxxx/db
HenPlus II connecting
url 'jdbc:sybase:Tds:localhost:xxxx/db
driver version 6.0
JZ004: DriverManager.getConnection(..., 属性) 中缺少用户名属性。
============ authorization required ===
Username: xxxx
Password:
出現底下訊息就表示連結上囉
Adaptive Server Enterprise - ............
read uncommitted
read committed *
serializable
xxxx@sybase:db>
再來就是用SQL查詢啦~~
參考網址:
HenPlus - JDBC SQL-shell
Open Source SQL Clients in Java