3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Java h2database 接続 [ commons-dbutils ]

Last updated at Posted at 2013-12-12

メモ

Java MySQL 接続 [ commons-dbutils ] を h2 用に変更 (マアカワラナイ)


import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.h2.jdbcx.JdbcDataSource;

public class Main {

	public static final String URL = "jdbc:h2: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.setURL(URL);
		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", mapHandler,
					i, j).get("ANS"));
		}
	}

}

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?