LoginSignup
1
0

More than 5 years have passed since last update.

Java hsqldb 接続 [ commons-dbutils ]

Last updated at Posted at 2013-12-12

メモ

Java MySQL 接続 [ commons-dbutils ] を hsqldb 用に変更 (マアカワラナイ)
SELECT * FROM DUAL 的な書き方がちょっと特殊


import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.hsqldb.jdbc.JDBCDataSource;

public class Main {

    public static final String URL = "jdbc:hsqldb:file:test";
    public static final String DBNAME = "test";
    public static final String USER = "sa";
    public static final String PASS = "";

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

        MapHandler mapHandler = new MapHandler();

        JDBCDataSource dataSource = new JDBCDataSource();

        dataSource.setDatabaseName(DBNAME);
        dataSource.setUser(USER);
        dataSource.setPassword(PASS);

        QueryRunner runner = new QueryRunner(dataSource);

        for (int i = 0, j = 10; i < 10; i++, j = j << 2) {
            System.out.println(runner.query(
                    "SELECT ? + ? AS ANS FROM (VALUES(0))", mapHandler, i, j)
                    .get("ANS"));
        }
    }

}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0