Nov 17, 2005
tinySQL にチャレンジ
tinySQL とは
tinySQL は Pure Java の RDBMS。
どうも何かの書籍で使用されたサンプルアプリケーションらしい。
色々試してみたのだが、結局 insert が全く動作しなかった。
当然 select、update、delete も試しようがない。
というわけで、あっさりと使い物にならないことが判明。
まぁ、書籍のサンプルだし。
とりあえず create table、drop table だけは動作した。
↓はそのサンプルコード。意味はないけれども。
tinySQL の実行環境構築
- tinySQL(tinySQL.jar) ver.2.0 をクラスパスに追加
サンプルコード
package jp.in_vitro.codelets.tinysql;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
public class Codelet {
public Codelet() throws ClassNotFoundException {
super();
}
public static void main(final String[] args) throws SQLException,
ClassNotFoundException, InstantiationException,
IllegalAccessException {
Codelet me = new Codelet();
me.execute();
}
protected void execute() throws InstantiationException,
IllegalAccessException, ClassNotFoundException, SQLException {
this.initializeDBMS();
try {
try {
// テーブルの生成。
this.createTable();
} catch (SQLException e) {
// 既に Table が生成済みの可能性があるので・・・
}
// insert が全く動作しないので、select、update、delete も試しようがない・・・
// テーブルの削除。
this.dropTable();
} finally {
this.destroyDBMS();
}
}
protected void initializeDBMS() throws ClassNotFoundException {
Class.forName("com.sqlmagic.tinysql.textFileDriver");
}
protected void destroyDBMS() {
}
protected Connection getConnection() throws SQLException {
String url = "jdbc:tinySQL";
return DriverManager.getConnection(url);
}
protected void createTable() throws SQLException {
Connection connection = this.getConnection();
try {
Statement statement = connection.createStatement();
statement.executeUpdate("CREATE TABLE sample (field01 INT)");
connection.commit();
connection.close();
} finally {
if (connection != null) {
connection.close();
}
}
}
protected void dropTable() throws SQLException {
Connection connection = this.getConnection();
try {
Statement statement = connection.createStatement();
statement.executeUpdate("DROP TABLE sample");
connection.commit();
connection.close();
} finally {
if (connection != null) {
connection.close();
}
}
}
}
TrackBack ping me at
http://www.in-vitro.jp/blog/index.cgi/Library/20051117_01.trackback
writeback message: Ready to post a comment.
