顯示具有 java 標籤的文章。 顯示所有文章
顯示具有 java 標籤的文章。 顯示所有文章

2009-06-01

取得MySQL中的自動字串

EX:
Table 型態 : survey ( SurveyId int unsigned not null auto_increment ,
SurveyName varchar(20) not null ,
SurveyTemplateId varchar(5) not null)

Statement stmt;
stmt.executeUpdate ( " insert into survey ( SurveyName , SurveyTemplateId ) values( ' Name ' , ' Id ' );

int autoIncKeyFromFunc = -1;
ResultSet rs = stmt.executeQuery("SELECT LAST_INSERT_ID()");
if (rs.next())
autoIncKeyFromFunc = rs.getInt(1);
rs.close();

autoIncKeyFromFunc就是自動字串

取的方法好像好幾種,這只是其中一種

Java-壓縮檔案之中文檔名也行

由於java內建的zip壓縮無法解決中文的檔名
拜辜狗大神所賜輕鬆找到解答:
使用apache的tool.zip "ant.jar"
辜狗大神是說湯姆貓有內健但我沒看到可能是阿帕契吧
由於不太相信湯姆貓沒有(因為我之前好像看過這個jar)
後來搜尋一下
竟然在eclipse中找到....
真神奇

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import org.apache.tools.zip.ZipOutputStream;

private void zip(String zipFileName, File inputFile) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
zip(out, inputFile, "");
out.close();
}
private void zip(ZipOutputStream out, File f, String base) throws Exception {
if (f.isDirectory()) {
File[] fl = f.listFiles();
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base + File.separator));
base = base.length() == 0 ? "" : base + File.separator;
for (int i = 0; i < fl.length; i++)
zip(out, fl[i], base + fl[i].getName());
}else {
out.putNextEntry(new org.apache.tools.zip.ZipEntry(base));
FileInputStream in = new FileInputStream(f);
int b;
while ( (b = in.read()) != -1)
out.write(b);
in.close();
}
}