2010年11月11日木曜日

H2 DatabaseとJCIFSでWindows共有上にディレクトリを作成する関数を作成する

H2 DatabaseとJCIFSでWindows共有上にディレクトリを作成する関数を作成するには、以下のスクリプトを実行します。

create alias if not exists jcifs_mkdirs as $$ 
import java.io.*;
import java.sql.*;
import org.h2.tools.*;
import jcifs.smb.*;
@CODE
int jcifs_mkdirs(String domain,
String user, String password, String server,
String path)
throws Exception
{
if( domain == null ){
throw new Exception("domain is not specified.");
}
user = (user == null)?"":user;
password = (password == null)?"":password;
if( server == null ){
throw new Exception("server is not specified.");
}
if( path == null ){
throw new Exception("path is not specified.");
}

SmbFile file = new SmbFile(
"smb://" + domain + ";" + user + ":" + password +
"@" + server + "/" + path
);

file.mkdirs();
return 0;
}
$$


実行例
call jcifs_mkdirs(
'LIFERAY1',
'test1', 'test1', 'liferay1',
'share/test_directory');


※システム環境変数CLASSPATHにtools.jarとJCIFSのjar
(jcifs-1.3.15.jar)を追加しておくこと。

動作環境
JDK6 Update 21, H2 Database 1.2.143 (2010-09-18), JCIFS 1.3.15
○関連情報
・H2 Databaseに関する他の記事はこちらを参照してください。

0 件のコメント:

コメントを投稿