2008年9月8日 星期一

Struts2 入門(一)

struts2 環境配置有空再寫,先來記錄一下實務coding 的部份
這邊是單純的query及insert,使用hibernate來操作DB 的部份。


一、 Java (Action的部份)

package com.blog;

import com.hibernate.hibernateUtil;
import com.opensymphony.xwork2.ActionContext;
import java.util.Map;
import org.hibernate.Session;
import org.hibernate.Transaction;
import orm.User;
import com.opensymphony.xwork2.ActionSupport;
import java.util.List;
import org.hibernate.Query;

public class blogAction extends ActionSupport {

public String execute() throws Exception {


init();

if (this.action != null && this.action.equals("a")) {

if (this.username != null && this.username != "") {
System.out.println("Ready to do save users");
this.SaveUsers();
}

} else if (this.action != null && this.action.equals("q")) {

System.out.println("Ready to do query users");
queryUser();
}


return "blog_add";
}

//初始化
private void init(){
session = ActionContext.getContext().getSession();
session.clear();
}

// Save Data To Pojo
private void SaveUsers() {

User user = new User();
user.setName(this.username);
user.setAge(age);

Session session = hibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();
session.save(user);
tx.commit();
session.close();

}

//query Data
private void queryUser() {

Session s = hibernateUtil.getSessionFactory().openSession();
Query q = s.createQuery("from User");
List l = q.list();

//set session
//ActionContext.getContext().getSession().put("blog", l);
session.put("blog", l);

// Map s =getSession();
// s.put("blog", age);
// this.setSession(s);
// Map s = ActionContext.getContext().getSession();
// s.put("blogSession", l);


// for(java.util.Iterator it = l.iterator(); it.hasNext();){
// User user = (User)it.next();
//System.out.println("User:"+user.getName());
// System.out.println(it.next());

// }

s.close();

}
private String username;
private int age;
private String action;
private Map session;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}
}

二、 JSP (View的部份)

<%--
Created on : 2008/9/8, 下午 02:33:31
Author : jimmy
--%>
< form action="blog.action" method="post">
< input type="text" name="username" value="" />

< input type="text" name="age" value="" />

< input type="hidden" name="action" value="a">
< input type="submit" value="Add" name="Add" />
< /form>

[session blog]
<!--input type="submit" value="query" name="query" /-->




< %
if( s ession.getAttribute("blog")!=null){
java.util.List blog = (j ava.util.List)session.getAttribute("blog");
if(blog!=null){
for(int i = 0 ; i < blog.size();i++){
out.println("");
orm.User user = (orm.User) blog.get(i);
out.println(""+user.getId()+"");
out.println(""+user.getName()+"");
out.println(""+user.getAge()+"");
out.println(""+"");
out.println("");
} } }
%>
< /table>

2008年9月4日 星期四

SQL常用 語法

參考來源:
http://www.1keydata.com/tw/sql/sql-create-index.html

http://www.tizag.com/mysqlTutorial/mysql-index.php

1. Create index

CREATE INDEX date_index ON bvl_txnlist(txndate_u,txndate_d)
CREATE TABLE bvl_txnlist (
name VARCHAR(50),
employeeID INT, INDEX (employeeID)
)


2. Alter Table

2.1 修改欄位名稱(將txndate 改為 txndate_u)

ALTER table bvl_txnlist change txndate txndate_u char(50)

2.2 修改欄位資料型態(將txndate 資料型態改為 varchar(30))

ALTER table bvl_txnlist modify txndate varchar(30)

2008年8月27日 星期三

Mac無法開機時的處理

資料來源: http://ca96.blogspot.com/2008/04/mac.html

當面臨到無法開機的情況時,首先要判斷的是屬於下列哪一種情況?

1. 空白的藍色或灰色畫面:可能是由磁碟權限、第三方軟體、或偶發的硬體問題所造成的。適用招式:ㄧ、二、三、四

2. 出現 "NO"、壞掉的資料夾或閃動的問號:這是由於 Mac 找不到開機所需的系統,可能是磁碟問題所致。適用招式:三、四

3. 黑色畫面,沒有聲音:你所碰到的可能是電力問題、主機板上的電池壞掉、故障的記憶體或其他的硬體問題


。第一招:以安全模式開機,開機快捷鍵:Shift
Step1: 開機時按住 Shift 鍵不放
Step2: 直到螢幕上出現灰色蘋果標誌及旋轉的齒輪時才放開Shift鍵
Step3: 如果順利啟動,“Safe Boot”字樣應該會在啟動時出現或在顯示於登入視窗中(以安全模式啟動會比一般啟動花更多的時間,因為系統會為開機磁碟進行磁軌檢查。耐著性子吧!若要離開安全模式,將電腦重新開機,並且不要在開機時按任何鍵即可。 )


。第二招:單一使用者模式,開機快捷鍵:Command(蘋果鍵) + S
Step1: 開機時按住 Command + S。如果看到黑底白字的文字模式,別嚇到了,這是正常的
Step2: 在游標後輸入 fsck - fy
Step3: 之後按 return 鍵。如果回覆的訊息是 " File System was Modified ",重複第二步驟直到系統回覆 " No problems were found "
Step4: 輸入 reboot 並按 return 鍵。(之後電腦就會重新開機了,如果順利就會進入系統,如果還是不行,那就試試其他的招式吧!)

其他解決方案:AppleJack(注1)
如果你在你的MAC 出問題之前曾安裝過 AppleJack,那麼過程就會簡單許多
1.輸入"applejack auto restart",之後按 return 鍵
2.稍待個幾分鐘,你的 MAC 將會重新開機並完成所有的修護作業


。第三招:用蘋果 CD/DVD 開機,開機快捷鍵﹕C
Step1: 放入 Mac OS X 安裝光碟(開機時壓住滑鼠不放即可打開光碟托盤[退片])
Step2: 開機時按住 C 鍵,直到灰色蘋果標誌出現在螢幕上才放手
Step3: Mac OS X 10.4.x的使用者:從選單列選擇「工具程式」> 「磁碟工具程式」
Step4: 從左側列出的硬碟圖示中選擇自己的硬碟,然後單點修理工具分頁中的「修復磁碟」。
Step5: 磁碟回報正常後,單點「修復磁碟權限」
Step6: 之後重開機,並在開機時不要按任何按鍵


。第四招:硬碟模式,開機快捷鍵:T
當其他的招式都失效時,硬碟模式可以讓你透過其他電腦來存取你的硬碟。這樣一來你就可以執行一些診斷、維護或者備份重要的工作檔案。
Step1: 開機時按住 T 鍵,直到看見 FireWire 圖示才放開。
Step2: 用一條 FireWire 線將故障的 Mac 接上正常的 Mac。
Step3: 開啟正常 Mac 上的磁碟工具程式 ( 位於應用程式 / 工具程式 )。
Step4: 從左側列出的硬碟圖示中選擇故障的硬碟,然後單點修理工具分頁中的「修復磁碟」。
Step5: 如果在正常 Mac 的桌面上可以看的到故障 Mac 的硬碟圖示,那麼說不定還可以把一些重要的檔案復原或者備份起來。


(注1):AppleJack 是一個專為 MAC OSX 開發的系統維護工具,當無法進入系統的圖形介面而手邊又沒有可開機的光碟時,AppleJack 可以在單一使用者模式下,以選單的方式協助使用者進行障礙排除。

2008年8月11日 星期一

javaMail(一)



Setup


If you use Java 2 Platform,
Enterprise Edition (J2EE) 1.3, you're in luck: it includes JavaMail, so
no additional setup is required. If, however, you're running Java 2
Platform, Standard Edition (J2SE) 1.1.7 and upwards, and you want email
capability for your applications, download and install the following:


資料來源: http://www.javaworld.com/javaworld/jw-10-2001/jw-1026-javamail.html?

Sample

以下的範例,以gmail 為例

package com.mail;

import java.security.Security;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class msgsendsample {

private static final String SMTP_HOST_NAME = "smtp.gmail.com";
private static final String SMTP_PORT = "465";

private static final String emailMsgTxt = "Test Message Contents";
private static final String emailSubjectTxt = "A test from gmail test.....";
private static final String emailFromAddress = "xxxx@gmail.com";
private static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
private static final String[] sendTo = {"xxxx@gmail.com","xxxx@yahoo.com.tw"};

msgsendsample() {
}

public void sendMail() throws MessagingException {

Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());

new msgsendsample().sendSSLMessage(sendTo, emailSubjectTxt,
emailMsgTxt, emailFromAddress);
System.out.println("Sucessfully Sent mail to All Users");

}

public void sendSSLMessage(String recipients[], String subject,
String message, String from) throws MessagingException {
boolean debug = true;

Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.port", SMTP_PORT);
props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
props.put("mail.smtp.socketFactory.fallback", "false");



Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("xxxx", "xxxx"); //Gmail的帳號及密碼
}
});


session.setDebug(debug); // 方便Debug用

Message msg = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);

InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);

// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}

public static void main(String args[]) throws Exception {

msgsendsample ms = new msgsendsample();
ms.sendMail();
}


}

p.s 一開始我只下載了javamail 所以在run的過程當中會出現 java.lang.NoClassDefFoundError: javax/activation/DataSource ,後來下載 javaBean Activation Framework加到Lib之後就解決了




2008年7月18日 星期五

PAV3檔暫存(讀檔、寫檔的範例)


以下包括 讀檔、寫檔的範例。



public class PAV3 {

public static final String Left = "L";

public static final String Right = "R";

private String BLD_DNLOAD = "/Users/macbook/java/test/FTP_DIR/BLD_DNLOAD";

private String PAV3 = "";

private String LST3_FILE = "";
private String BV1_FILE = "";
private String BV2_FILE = "";
private String BV3_FILE = "";

public void run(String path) {
this.BLD_DNLOAD = path;
}



//先讀取舊的 PAV3.DAT
public Map ReadPAV3() {

ArrayList<String> newList = new ArrayList<String>();
Map newMap = new HashMap(2);

PAV3 = BLD_DNLOAD + "//PAV3.DAT";

FileReader f;
BufferedReader br;


try {
f = new FileReader(PAV3);
br = new BufferedReader(f);

String strLine;

while ((strLine = br.readLine()) != null) {

if(strLine.startsWith("H")){
newMap.put("header", strLine);
}else if(strLine.startsWith("D")){
if(!this.isExistHIJK(strLine)){
//System.out.println("["+strLine+"]");
newList.add(strLine);
}
}else{

}
}
newMap.put("detail", newList);

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return newMap;
}



public void run() {

//先讀取舊的 PAV3.DAT
Map oldMap = ReadPAV3();

File f = new File(BLD_DNLOAD);
File[] files = f.listFiles();
TreeMap tm = new TreeMap();

ArrayList<String> al_LST3 = new ArrayList<String>();
ArrayList<String> al_BV1 = new ArrayList<String>();
ArrayList<String> al_BV2 = new ArrayList<String>();
ArrayList<String> al_BV3 = new ArrayList<String>();
ArrayList<String> al_hijk = new ArrayList<String>();

for (int i = 0; i < files.length; i++) {

if (!files[i].isDirectory()
&& !files[i].getName().startsWith(".DS_Store")) {

String filename = files[i].getName();

String sysDate = this.retriSysDate();
String fileDate = this.retriveFileDate(filename);

// 檔案日期 大於或等於 系統日
if (this.compare(fileDate, sysDate)) {

if (this.whichHIJK(filename).equals("i")) {
al_LST3.add(filename);
} else if (this.whichHIJK(filename).equals("j")) {
al_BV1.add(filename);
} else if (this.whichHIJK(filename).equals("k")) {
al_BV2.add(filename);
} else if (this.whichHIJK(filename).equals("h")) {
al_BV3.add(filename);
}

} else {

if (this.whichHIJK(filename).equals("i")) {
if (this.compare(fileDate, LST3_FILE)) {
LST3_FILE = filename;
}
} else if (this.whichHIJK(filename).equals("j")) {
if (this.compare(fileDate, LST3_FILE)) {
BV1_FILE = filename;
}
} else if (this.whichHIJK(filename).equals("k")) {
if (this.compare(fileDate, LST3_FILE)) {
BV2_FILE = filename;
}
} else if (this.whichHIJK(filename).equals("h")) {
if (this.compare(fileDate, LST3_FILE)) {
BV3_FILE = filename;
}
}

}

}

}

if (!LST3_FILE.equals("")) al_LST3.add(LST3_FILE);
if (!BV1_FILE.equals("")) al_BV1.add(BV1_FILE);
if (!BV2_FILE.equals("")) al_BV2.add(BV2_FILE);
if (!BV3_FILE.equals("")) al_BV3.add(BV3_FILE);

al_hijk.addAll(al_LST3);
al_hijk.addAll(al_BV1);
al_hijk.addAll(al_BV2);
al_hijk.addAll(al_BV3);

tm.put("HIJK", al_hijk);
// tm.put("BV1", al_BV1);
// tm.put("BV2", al_BV2);
// tm.put("BV3", al_BV3);

String b = this.buildPav3(tm,oldMap);

System.out.println(b);

}



//產生 PAV3.DAT
public String buildPav3(TreeMap tm,Map oldmap) {


StringBuilder b = new StringBuilder();
// String company = "0001";

// header
//b = this.header(b, company);
b.append(oldmap.get("header")).append("\n");


// detail

int s = 0;

ArrayList l0 = (ArrayList)oldmap.get("detail");

for (java.util.Iterator<String> it = l0.iterator(); it.hasNext();) {
String olddetail = it.next();
b.append(olddetail).append("\n");
s++;
}

List l1 = (ArrayList) tm.get("HIJK");
for (java.util.Iterator<String> it = l1.iterator(); it.hasNext();) {
String filename = it.next();
b = this.detail(b, filename);
s++;
}


// trailer
b = this.trailer(b, s);

//update PAV3
this.writeToPAV3(b.toString());

return b.toString();
}


public void writeToPAV3(String p){

File saveFile=new File(PAV3);
try
{
FileWriter fwriter=new FileWriter(saveFile);
fwriter.write(p);
fwriter.close();
}
catch(Exception e)
{
e.printStackTrace();
}

}


// header
public StringBuilder header(StringBuilder b, String com) {
// 1.
b.append("H");
// 2.
b.append(" ");
// 3.4.
b.append(this.retriSysDateTime());
// 5.
b.append(com);
// 6.
for (int i = 0; i < 12; i++) {
b.append(" ");
}
// 7.
b.append("\n");

return b;
}

// detail
public StringBuilder detail(StringBuilder b, String filename) {
// 1.
b.append("D");
// 2.
b.append(" ");
// 3.
b.append(this.fillZero(filename, 30, "L"));
// 4.
b.append("\n");
return b;
}

// trailer
public StringBuilder trailer(StringBuilder b, int t) {
// 1.
b.append("T");
// 2.
b.append(" ");
// 3.
b.append(this.fillZero(t, 6, "R"));
// 4.
for (int i = 0; i < 24; i++) {
b.append(" ");
}
// 5.
b.append("\n");
return b;
}

// 左邊補0
public String LeftZero(int f, int len) {

String totalcount = "";
String count = String.valueOf(f);
int l = count.length();

for (int j = 0; j < len - l; j++) {
totalcount += "0";
}
totalcount += count;
return totalcount;
}

// 右邊補0
public String RightZero(int f, int len) {

String totalcount = "";
String count = String.valueOf(f);
int l = count.length();
totalcount += count;
for (int j = 0; j < len - l; j++) {
totalcount += "0";
}

return totalcount;
}

// 系統日與FileDate做比較
public boolean compare(String sysDate, String fileDate) {

// System.out.println("Compare:"+sysDate+'/'+fileDate);
if (fileDate.equals(""))
fileDate = "19000000";
if (sysDate.compareTo(fileDate) >= 0) {
return true;
} else {
return false;
}
}

//判斷是否存在文件代碼是 h,i,j,k
public boolean isExistHIJK(String strLine){

if(StringUtils.contains(strLine, "TBLD") || StringUtils.contains(strLine, "BV_")){
return true;
}
return false;

}

// 補0
// Example
// p.fillZero(21, 5, "R") ==>21000
// p.fillZero(21, 5, "L") ==>00021

private String fillZero(int f, int len, String LR) {

String totalcount = "";
String count = String.valueOf(f);
int l = count.length();
if (LR.equalsIgnoreCase(this.Right)) {
totalcount += count;
}
for (int j = 0; j < len - l; j++) {
totalcount += "0";
}
if (!LR.equalsIgnoreCase(this.Right)) {
totalcount += count;
}
return totalcount;

}

public String fillZero(Object f, int len, String LR) {

String totalcount = "";
String count = String.valueOf(f);
int l = count.length();
if (LR.equalsIgnoreCase(this.Right)) {
totalcount += count;
}
for (int j = 0; j < len - l; j++) {
totalcount += "0";
}
if (!LR.equalsIgnoreCase(this.Right)) {
totalcount += count;
}
return totalcount;
}

public boolean isHIJK(String filename) {

if (filename.toUpperCase().startsWith("TBLD")
|| filename.toUpperCase().startsWith("BV_UPDATE3")
|| filename.toUpperCase().startsWith("BV_STARTUP3")
|| filename.toUpperCase().startsWith("BV_MAIN3")) {
return true;
}
return false;
}

public String whichHIJK(String filename) {

if (filename.toUpperCase().startsWith("TBLD")) {// h
return "h";
} else if (filename.toUpperCase().startsWith("BV_UPDATE3")) {// i
return "i";
} else if (filename.toUpperCase().startsWith("BV_STARTUP3")) {// j
return "j";
} else if (filename.toUpperCase().startsWith("BV_MAIN3")) {// k
return "k";
}
return "";
}

public String retriveFileDate(String filename) {

// System.out.println(filename+'/'+filename.length());
if (filename.toUpperCase().startsWith("TBLD")
&& filename.length() == 17) {// h
return filename.substring(5, 13);
} else if (filename.toUpperCase().startsWith("BV_UPDATE3")
&& filename.length() == 19) {// i
return filename.substring(11, 19);
} else if (filename.toUpperCase().startsWith("BV_STARTUP3")
&& filename.length() == 20) {// j
return filename.substring(12, 20);
} else if (filename.toUpperCase().startsWith("BV_MAIN3")
&& filename.length() == 21) {// k
return filename.substring(9, 17);
}
return "00000000";
}

//取得系統時間
public String retriSysDate() {
Calendar cl = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(cl.getTime());
}

public String retriSysDateTime() {
Calendar cl = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
return sdf.format(cl.getTime());
}



}

2008年7月7日 星期一

Java 讀檔(使用BufferReader)




String fileName1 = "/Users/macbook/java/test/IC080329.G02";



FileReader f;
BufferedReader br;
SimpleConnection sc = new SimpleConnection();
Connection con = null;

try {
f = new FileReader(fileName1);
br = new BufferedReader(f);
String strLine;
int i = 0;
con = sc.getConnection();
while ((strLine = br.readLine()) != null) {

//長度為135,為了防止表頭及表
if(strLine.length()>100){
//System.out.println("["+strLine.length()+"]"+strLine);
separate(strLine);
if(save2db(con)){
System.out.println("第"+i+"筆匯入成功!");
}
// print();
}
i++;
}

} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}finally{
sc.freeConnection(con);
}


2008年7月1日 星期二

mysql tutorial


1.tutorial
http://dev.mysql.com/doc/refman/5.0/en/tutorial.html

2008年6月29日 星期日

Instanceof 測試

如果要用來判斷傳入的是那種型態,參考如下 :

public class InstanceoftTest {


InstanceoftTest(){

String s = "this is String";
Integer i = new Integer(1);
BigDecimal b = new BigDecimal(2.34);
checkWithInstanceof(s);
checkWithInstanceof(i);
checkWithInstanceof(b);
}

public static void checkWithInstanceof(Object o){

if(o instanceof Integer){
System.out.println("Your Class Type is Integer");
}else if(o instanceof BigDecimal){
System.out.println("Your Class Type is BigDecimal");
}else{
System.out.println("Your Class Type will conver String");
}
}



}

2008年6月26日 星期四

學習 jQuery (一)

1.why jQuery

寫過javascript來操作Dom是很麻煩的,jQuery可以比較簡單的來取出相關的Element。
jQuery 所有的 API 都是定義在 jQuery 這個物件下,沒有對 JavaScript 原生的物件作任何修改。
同時 jQuery 的 selector(取得網頁物件的 API)符合 CSS 的語法,同時寫 jQuery 及 CSS 一點都不會錯亂。

2.Download JQuery

網站上有三個版
1.jquery-xxxx.js
這是 jQuery 程式碼最好讀的版本,如果你打算研究 jQuery 的原始程式碼,那下載這個版本是最清楚的。
2.jquery-xxxx.min.js
這個版本與 1. 是一樣的程式碼,只不過把多餘的空白或是換行給拿掉,以便讓整個 js 檔案大小可以下降,
在上線的網站上使用這個版本可以讓使用者下載量變少一點,以提升整個頁面的載入速度。
3.jquery-xxxx.pack.js
這個版本把原本 jQuery 的程式碼作了「壓縮」,也就是有一些名稱代換的方式把 code size 進行更進一步的塑身。
不過因為它用了 eval() 這個函式,所以 JavaScript 的載入會稍微延遲一點時間。

3.第一個jQuery程式


<html>
<head>
<title>jQuery Tutorial 1</title>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<script type="text/javascript" src="../js/jquery.js"></script>
<script type="text/javascript">
function showMsg(e) {
$(e.target).attr('disabled', true);
if ($('#msg').html().length == 0) {
$('#msg').html('<h1>Hello</h1>');
}
$('#msg').fadeIn();
setTimeout(function(){
$('#msg').fadeOut();
$(e.target).attr('disabled', false);
}, 3000);
}

$(document).ready(function(e){
$('#btn').click(showMsg);
});
</script>
</head>
<body>
<div id="msg"></div>
<input type="button" value="Click Me" id="btn"/>
</body>
</html>


4. UI plug in


4.1 UI plug : http://ui.jquery.com/themeroller
4.2 UI plug in API: http://docs.jquery.com/UI

2008年6月25日 星期三

從web.xml取出變數


如果想取出web.xml裡的key-value,做法如下:

1. web.xml設定

<context-param>
<param-name>notebook</param-name>
<param-value>1</param-value>
</context-param>

2. 在程式做法(以下做法是在JSF下)

private FacesContext fc = FacesContext.getCurrentInstance();
//透過facesContext可取得httpSession
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
//可取出初始化變數(name="notebook")
String a = session.getServletContext().getInitParameter("notebook");

if(null!=a && a.equals("1")) {
cps_tbld_dir ="//users//macbook//java//test//FTP_DIR//TBLD";
}

2008年6月24日 星期二

Java: System Properties

來源: http://www.leepoint.net/notes-java/io/30properties_and_preferences/40sysprops/10sysprop.html

From System Properties you can find information about the operating system, the user, and the version of Java.

The property names (keys) and values are stored in a Properties structure. (See Properties). A Properties object can also be used to store your own program properties in a file.


Getting the System Properties

Typically you get one property at a time by supplying the key in a call to System.getProperty().

  • String System.getProperty(String key)
    Returns the value of property key as a String.
  • String System.getProperty(String key, String default)
    Returns the value of property key as a string, or default if the property did not exist.
  • Properties System.getProperties()
    Returns a Properties object which has the value of all the properties. There are several ways to work with this object; see below for one example.

Example

String userDir = System.getProperty("user.dir");

A list of system properties

Here are the properties that displayed on my system.

Here are the properties that displayed on my system.

awt.toolkit=sun.awt.windows.WToolkit
file.encoding=Cp1252
file.encoding.pkg=sun.io
file.separator=\
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.awt.printerjob=sun.awt.windows.WPrinterJob
java.class.path=.;c:\classpath\com.fredswartz.utilities.jar;c:\classpath\TableLayout.jar;c:\classpath\swixml.jar;c:\classpath\jdom.jar;c:\classpath\pmd-1.8\lib\pmd-1.8.jar;C:\classpath\pmd-1.8\lib\jaxen-core-1.0-fcs.jar;C:\classpath\com.fredswartz.guiUtils.jar;C:\classpath\com.fredswartz.fmt-0.7.jar;C:\Program Files\IBM\Cloudscape_10.0\lib\derby.jar
java.class.version=49.0
java.endorsed.dirs=C:\Program Files\Java\jdk1.5.0_01\jre\lib\endorsed
java.ext.dirs=C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext
java.home=C:\Program Files\Java\jdk1.5.0_01\jre
java.io.tmpdir=C:\DOCUME~1\Owner\LOCALS~1\Temp\
java.library.path=C:\Program Files\Java\jdk1.5.0_01\bin;.;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;c:\Python22;C:\Program Files\PC-Doctor for Windows\services;c:\ant\bin;c:\Program Files\Java\jdk\bin;c:\Program Files\Java\jdk\jre\javaws;C:\Program Files\Sybase\Adaptive Server Anywhere 6.0\win32;c:\classpath\jcsc/bin;c:\classpath\jcsc\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin
java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition
java.runtime.version=1.5.0_01-b08
java.specification.name=Java Platform API Specification
java.specification.vendor=Sun Microsystems Inc.
java.specification.version=1.5
java.vendor=Sun Microsystems Inc.
java.vendor.url=http://java.sun.com/
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi
java.version=1.5.0_01
java.vm.info=mixed mode, sharing
java.vm.name=Java HotSpot(TM) Client VM
java.vm.specification.name=Java Virtual Machine Specification
java.vm.specification.vendor=Sun Microsystems Inc.
java.vm.specification.version=1.0
java.vm.vendor=Sun Microsystems Inc.
java.vm.version=1.5.0_01-b08
line.separator=

os.arch=x86
os.name=Windows XP
os.version=5.1
path.separator=;
sun.arch.data.model=32
sun.boot.class.path=C:\Program Files\Java\jdk1.5.0_01\jre\lib\rt.jar;C:\Program Files\Java\jdk1.5.0_01\jre\lib\i18n.jar;C:\Program Files\Java\jdk1.5.0_01\jre\lib\sunrsasign.jar;C:\Program Files\Java\jdk1.5.0_01\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.5.0_01\jre\lib\jce.jar;C:\Program Files\Java\jdk1.5.0_01\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.5.0_01\jre\classes
sun.boot.library.path=C:\Program Files\Java\jdk1.5.0_01\jre\bin
sun.cpu.endian=little
sun.cpu.isalist=pentium_pro+mmx pentium_pro pentium+mmx pentium i486 i386 i86
sun.desktop=windows
sun.io.unicode.encoding=UnicodeLittle
sun.jnu.encoding=Cp1252
sun.management.compiler=HotSpot Client Compiler
sun.os.patch.level=Service Pack 2
user.country=US
user.dir=C:\0www-workingnotes\notes-java-working\io\30properties_and_preferences\40sysprops\SysPropList
user.home=C:\Documents and Settings\Owner
user.language=en
user.name=Owner
user.timezone=
user.variant=

public void SysOsName(){

Properties pr = System.getProperties();
//取得os的名稱
String osName = pr.getProperty("os.name");
if(osName.toLowerCase().subSequence(0,3).equals("mac")){
System.out.println(" Your Computer OS System is Mac Os");
}

2008年6月13日 星期五

java讀檔筆記

這是一個binary Code 讀檔的範例,格式如下

1 Application status
12 FileName
8 Data Application
2 "\n\n"


長度共1+12+8+2 = 23

以下範例是長度會部是92,每個陣例長度為 23,所共陣例長度為4

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;


public class G2CLogFileRead {

private static final int len = 23;

public void run(){
String fileName = "/Users/macbook/java/test/REF00906.BVA";
run(fileName);
}

public void run(String fileName){

try {

File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
DataInputStream dis = new DataInputStream(fis);
ByteArrayOutputStream bos = new ByteArrayOutputStream();

int b = dis.read();

while (b > -1) {
bos.write(b);
b = dis.read();
}
byte[] ba = bos.toByteArray();

/* Every File length is 23 */
int fileSize = ((ba.length+1)/len);

String[] fName = new String[fileSize];
int k =0;
StringBuilder s = new StringBuilder();

for(int j = 1 ; j <= ba.length;j++){
s.append((char)(ba[j-1]));
if(j%len==0){
fName[k] = s.toString();
s.delete(0,len);
k++;
}
}

for(int f = 0 ; f< fName.length;f++){
System.out.print(fName[f]);
}


bos.close();
dis.close();

} catch (Exception e) {
System.out.println("IOException: " + e);
}

}


public void parseLog(int[] b) {

System.out.println(b);
}



/**
* @param args
*/
public static void main(String[] args) {

G2CLogFileRead g = new G2CLogFileRead();
/*
if ( args.length== 1 ){
String fileName = args[0];
}else{
System.out.println( "CPSLogTest filename");
return;
}

g.run(args[0]);
*/
g.run();

}

}

2008年6月8日 星期日

如何移除 mac 上的 mysql

若要移除MySQL,請先登入成root,系統最高權限管理者的帳號,將"/usr/local/mysql-版本號碼/data/"檔案夾內,已建立的重要資料庫檔案夾,複製備份出來,再直接將"/usr/local/mysql-版本號碼"這個子目錄直接刪除,
另外在 /資源庫/Receipt/mysql-版本號碼.pkg這個檔案也順便刪除,即完成MySQL在MacOSX平台的軟體移除程序。

相關參考連結
http://www.j2h.tw/bbs/bbs16/150.html
http://www.comentum.com/mysql-administration.html



2008年5月29日 星期四

ReadLogFile測試

主要是要讀檔並使用二階的treeMap方式來存放

1. test.log

C01,01,A,10
C02,04,A,15
C03,05,A,10
C02,06,A,20
C01,09,A,3
C01,10,C,7
C05,12,D,10
C05,13,A,0
C06,19,C,10

2. ReadLogFileTest.java

import java.io.*;
import java.util.*;

class LogData
{
private String cardNo;
private String seqNo;
private String txnType;
private String txnAmount;


public LogData(String [] sAry )
{
this.setCardNo(sAry[0]);
this.setSeqNo(sAry[1]);
this.setTxnType(sAry[2]);
this.setTxnAmount(sAry[3]);
}

public void setCardNo( String sCardNo )
{
cardNo = sCardNo;
}

public String getCardNo()
{
return cardNo;
}

public void setSeqNo( String sSeqNo )
{
seqNo = sSeqNo;
}

public String getSeqNo()
{
return seqNo;
}

public void setTxnType( String sTxnType )
{
txnType = sTxnType;
}

public String getTxnType()
{
return txnType;
}

public void setTxnAmount( String sTxnAmount )
{
txnAmount = sTxnAmount;
}

public String getTxnAmount()
{
return txnAmount;
}

public String print(){

StringBuffer sb = new StringBuffer();
sb.append("Card No : " + cardNo + "\n");
sb.append("Seq No : " + seqNo + "\n");
sb.append("Txn Type : " + txnType + "\n");
sb.append("txnAmount : " + txnAmount + "\n");

return sb.toString();
}

}


public class ReadLogFileTest {



public static void main(String [] args ) throws IOException
{

FileReader fr = new FileReader("test.log");
BufferedReader br = new BufferedReader(fr);

TreeMap &lt;String , TreeMap &gt; map = new TreeMap&lt;String , TreeMap&gt;() ;
TreeSet &lt;String&amp;gt;set = new TreeSet&lt;String&amp;gt;();

try
{
String s = new String();
while( (s = br.readLine()) != null )
{
System.out.println(s);
String [] strData = s.split(",");

LogData lg = new LogData(strData);

//System.out.println(lg.toString());

TreeMap &lt;String , LogData&gt; subMap = new TreeMap&lt;String , LogData&gt;() ;
subMap.put( lg.getSeqNo() , lg );
//System.out.println(subMap);

if(map.containsKey(lg.getCardNo())){
TreeMap tm = map.get(lg.getCardNo());
tm.put(lg.getSeqNo() ,lg);
map.put(lg.getCardNo() , tm );
}else{

map.put(lg.getCardNo() , subMap );
set.add(lg.getCardNo());
}

}


//System.out.println("TreeMap Size:"+map.size());

Iterator it =set.iterator();
while(it.hasNext()){
String k = (String)it.next();
TreeMap &lt;String , LogData&gt; tm = map.get(k) ;
//System.out.println("["+k+"]"+tm);
System.out.println("["+k+"]");
Collection collection = tm.values();
Iterator iterator = collection.iterator();

while(iterator.hasNext()) {
LogData lg =(LogData)iterator.next();
//System.out.println(iterator.next());
System.out.println(lg.print());
}


}





}catch( Exception e){
System.out.println("Exception : " + e );
}finally{
br.close();
}
}


}

2008年5月26日 星期一

System.getProperty()参数大全

# java.version Java Runtime Environment version
# java.vendor Java Runtime Environment vendor
# java.vendor.url Java vendor URL
# java.home Java installation directory
# java.vm.specification.version Java Virtual Machine specification version
# java.vm.specification.vendor Java Virtual Machine specification vendor
# java.vm.specification.name Java Virtual Machine specification name
# java.vm.version Java Virtual Machine implementation version
# java.vm.vendor Java Virtual Machine implementation vendor
# java.vm.name Java Virtual Machine implementation name
# java.specification.version Java Runtime Environment specification version
# java.specification.vendor Java Runtime Environment specification vendor
# java.specification.name Java Runtime Environment specification name
# java.class.version Java class format version number
# java.class.path Java class path
# java.library.path List of paths to search when loading libraries
# java.io.tmpdir Default temp file path
# java.compiler Name of JIT compiler to use
# java.ext.dirs Path of extension directory or directories
# os.name Operating system name
# os.arch Operating system architecture
# os.version Operating system version
# file.separator File separator ("/" on UNIX)
# path.separator Path separator (":" on UNIX)
# line.separator Line separator ("\n" on UNIX)
# user.name User's account name
# user.home User's home directory
# user.dir User's current working directory

2008年5月22日 星期四

jimmy's mac mysql my.cnf

# Example MySQL config file for medium systems.
#
# This is for a system with little memory (32M - 64M) where MySQL plays
# an important part, or systems up to 128M where MySQL is used together with
# other programs (such as a web server)
#
# You can copy this file to
# /etc/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is /usr/local/mysql/data) or
# ~/.my.cnf to set user-specific options.
#
# In this file, you can use all long options that a program supports.
# If you want to know which options a program supports, run the program
# with the "--help" option.

# The following options will be passed to all MySQL clients
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
default-character-set=utf8

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
key_buffer = 16M
max_allowed_packet = 1M
table_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
default-character-set=utf8
default-collation=utf8_general_ci

# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
#
#skip-networking

# Replication Master Server (default)
# binary logging is required for replication
log-bin=mysql-bin

# required unique id between 1 and 2^32 - 1
# defaults to 1 if master-host is not set
# but will not function as a master if omitted
server-id = 1

# Replication Slave (comment out master section to use this)
#
# To configure this host as a replication slave, you can choose between
# two methods :
#
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -
# the syntax is:
#
# CHANGE MASTER TO MASTER_HOST=&lt;host&amp;gt;, MASTER_PORT=&lt;port&amp;gt;,
# MASTER_USER=&lt;user&amp;gt;, MASTER_PASSWORD=&lt;password&amp;gt; ;
#
# where you replace &lt;host&amp;gt;, &lt;user&amp;gt;, &lt;password&amp;gt; by quoted strings and
# &lt;port&amp;gt; by the master's port number (3306 by default).
#
# Example:
#
# CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,
# MASTER_USER='joe', MASTER_PASSWORD='secret';
#
# OR
#
# 2) Set the variables below. However, in case you choose this method, then
# start replication for the first time (even unsuccessfully, for example
# if you mistyped the password in master-password and the slave fails to
# connect), the slave will create a master.info file, and any later
# change in this file to the variables' values below will be ignored and
# overridden by the content of the master.info file, unless you shutdown
# the slave server, delete master.info and restart the slaver server.
# For that reason, you may want to leave the lines below untouched
# (commented) and instead use CHANGE MASTER TO (see above)
#
# required unique id between 2 and 2^32 - 1
# (and different from the master)
# defaults to 2 if master-host is set
# but will not function as a slave if omitted
#server-id = 2
#
# The replication master for this slave - required
#master-host = &lt;hostname&amp;gt;
#
# The username the slave will use for authentication when connecting
# to the master - required
#master-user = &lt;username&amp;gt;
#
# The password the slave will authenticate with when connecting to
# the master - required
#master-password = &lt;password&amp;gt;
#
# The port the master is listening on.
# optional - defaults to 3306
#master-port = &lt;port&amp;gt;
#
# binary logging - not required for slaves, but recommended
#log-bin=mysql-bin

# Point the following paths to different dedicated disks
#tmpdir = /tmp/
#log-update = /path-to-dedicated-directory/hostname

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000

# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /usr/local/mysql/data/
#innodb_data_file_path = ibdata1:10M:autoextend
#innodb_log_group_home_dir = /usr/local/mysql/data/
#innodb_log_arch_dir = /usr/local/mysql/data/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
#innodb_buffer_pool_size = 16M
#innodb_additional_mem_pool_size = 2M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 5M
#innodb_log_buffer_size = 8M
#innodb_flush_log_at_trx_commit = 1
#innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

jimmy's mac .profile

export PS1='\u@\h[\e[33m\][\w]\[\e[0m\]\$'
export CLICOLOR="YES"
export LSCOLORS="GxgxFxdxCxDxDxhbadExEx"
export ANT_HOME="/Users/macbook/java/apache-ant-1.7.0"
export PATH=$ANT_HOME/bin:$PATH

2008年5月18日 星期日

清Log檔的方式

清Log檔的方式
1.截斷交易記錄檔
BACKUP LOG 'datadasename' WITH TRUNCATE_ONLY
2.顯示資料庫檔案,找出交易記錄檔的邏輯檔名
EXEC sp_helpdb 'datadasename'
3.壓縮交易記錄檔
DBCC SHRINKFILE('datadasename_Log',2)

==========另外一種解法==========

1.
DUMP TRANSACTION DBName WITH NO_LOG
2.進行mssql 2005壓縮

2008年5月13日 星期二

php 相關網站


1.Tutorial

[國外]

http://www.w3schools.com/PHP/DEfaULT.asP
http://devzone.zend.com/node/view/id/627
http://www.php-mysql-tutorial.com/
http://www.htmlgoodies.com/beyond/php/article.php/3472391
http://www.1keydata.com/php-tutorial/
[國內]
http://php.igt.com.tw/
http://203.68.102.46/phpx/modules/tadbook2/index.php?op=view_one_book&book_sn=3

[討論區]
http://www.phpdc.com/article_list/2/
http://www.php5.idv.tw/
http://twpug.net/modules/newbb/viewtopic.php?post_id=8316

2008年5月8日 星期四

jboss 亂碼問題

JBoss seam開發時候,使用EntityQuery,如果查詢條件輸入
中文,查詢後,結果會搜尋條件會變成亂碼,在參數傳遞也會有這個問題。

解決方式:
修改[JBoss Home]/server/default/deploy/jboss-web.deployer/server.xml,在
Connector port="8080" .....中增加URIEncoding="UTF-8" 後問題得到解決

2008年4月29日 星期二

seam gen 設定(mysql)

#Generated by seam setup
#Tue Apr 29 17:53:10 CST 2008
hibernate.connection.password=1234
workspace.home=/Users/macbook/project
model.package=com.infinitiessoft.prj.tcps
hibernate.default_catalog=cps
driver.jar=/Users/macbook/java/lib/mysql-connector-java-3.1.12-bin.jar
action.package=com.infinitiessoft.prj.tcps
test.package=com.infinitiessoft.prj.tcps
database.type=mysql
richfaces.skin=blueSky
hibernate.default_schema.null=
database.drop=y
project.name=tcps
hibernate.connection.username=cps
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
project.type=ear
icefaces.home=
database.exists=y
jboss.home=/Users/macbook/java/jboss-4.2.2.GA
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.url=jdbc\:mysql\://localhost\:3306/cps
icefaces=n

這是用jasper2.0.4最新版的實做

1.取出datasource
List sourceList = dao.rundata();
if(sourceList.size() < sourcelist =" java.util.Collections.EMPTY_LIST;
}

2.實作一個Map物作來存放變數
Map par = new HashMap();
par.put("par1", "par1-test1");
par.put("par2", "test2");

3.取出jasper檔案
File jasperFile= new File( config.getServletContext().getRealPath("/report/price.jasper"));

4.將.jasper File轉成jasperReport
JasperReport jr = (JasperReport) net.sf.jasperreports.engine.util.JRLoader.loadObject(jasperFile);

5.將sourceList 轉成 JRDataSource
net.sf.jasperreports.engine.JRDataSource jrds = new net.sf.jasperreports.engine.JREmptyDataSource();
jrds = new net.sf.jasperreports.engine.data.JRMapCollectionDataSource(sourceList);

6.從指定的jasperReport 檔案compiled成report design loaded
net.sf.jasperreports.engine.JasperPrint jp= JasperFillManager.fillReport(jr, par,jrds);

7.Exports the generated report object received as parameter into PDF format and returns the binary content as a byte array.
byte[] bytes = net.sf.jasperreports.engine.JasperExportManager.exportReportToPdf(jp);

8.將byte array透過response輸出成PDF
.
.
(略)
response.setHeader("Content-Disposition", "inline;filename=test.pdf");
response.reset();
if (bytes != null && bytes.length != 0) {
response.setContentLength(bytes.length);
ServletOutputStream os = response.getOutputStream();
os.write(bytes, 0, bytes.length);
} else {
throw new IllegalStateException("fail to create pdf file");
}
response.flushBuffer();
.(略)
.

2008年4月28日 星期一

mysql 變更密碼

mysql> set password for 'root'@'localhost' = password('1234');
mysql> flush privileges;

mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
-> WHERE User = 'root';
mysql> FLUSH PRIVILEGES;

2008年4月25日 星期五

讀檔寫檔簡單測試

package com.file;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class filereaderTest {

public void filereaderTest(){

try {

FileReader fr =new FileReader("/Users/macbook/java/test.txt");
BufferedReader br= new BufferedReader (fr);

//從檔案輸入資料流入緩衝器類別物件br
String line;
while ((line =br.readLine())!=null) {
System.out.println(line);
}
System.out.println("========讀檔成功=========");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("========找不到檔案,讀檔失敗=========");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("========讀檔失敗=========");
}

}


public void filewritetest(){

BufferedWriter bw;
try {
bw = new BufferedWriter (
new FileWriter("/Users/macbook/java/test1.txt"));
//輸出資料流入緩衝器後再輸出到系統標準輸出
String s="字元輸出資料流BufferedWriter測試234!";
bw.write( s, 0, s.length( ) ); //用write方法將s輸出

bw.close();

System.out.println("========寫檔成功=========");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("========寫檔失敗=========");
}

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new filereaderTest().filewritetest();

}

}

2008年4月22日 星期二

有興的血型

http://www.wretch.cc/blog/Amoral&article_id=23852262

2008年4月21日 星期一

mysql常用指令(一)

1.顯示DATABASE 所有的DB
mysql> SHOW DATABASES;
+-----------------------+
| Database |
+-----------------------+
|information_schema |
| TICP |
| foodmart |
| jasperserver |
| mysql |
| report |
| sowoo |
| sugarcrm |
| test |
+-----------------------+
9 rows in set (0.00 sec)


2. 顯示該 DB 的所有table
mysql> show tables from mysql;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| func |
| help_category |
| user |
| user_info |
+---------------------------+
18 rows in set (0.00 sec)

3. 指定使用某一個DB(這邊以mysql預設的為例)
mysql> USE MYSQL;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

4. 查詢資料
mysql> SELECT USER FROM USER;
+---------------+
| USER |
+--------------+
| jasperdb |
| root |
| root |
| jasperadmin |
| jimmy |
| root |
+--------------+
6 rows in set (0.00 sec)

在mac os上加上ant的環境變數

用vi 去.profile加上以下的二行

export ANT_HOME="/Users/macbook/java/apache-ant-1.7.0"
export PATH=$ANT_HOME/bin:$PATH