zoukankan      html  css  js  c++  java
  • H2 基本知识2

    首先下载H2 For Windows installer h2下载链接

    安装后在C:\Program Files\H2\src\test\org\h2\samples(默认安装) 文件夹下有很多sample 。

    看看sample 代码,很多就会了,

    先来个helloworld

    /*
     * Copyright 2004-2010 H2 Group. Multiple-Licensed under the H2 License, Version
     * 1.0, and under the Eclipse Public License, Version 1.0
     * (http://h2database.com/html/license.html). Initial Developer: H2 Group
     */
    package org.h2.samples;

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import org.h2.tools.DeleteDbFiles;

    /**
     * A very simple class that shows how to load the driver, create a database,
     * create a table, and insert some data.
     */
    public class HelloWorld {

        /**
         * Called when ran from command line.
         *
         * @param args ignored
         */
        public static void main(String... args) throws Exception {
            // delete the database named 'test' in the user home directory
            DeleteDbFiles.execute("~", "test", true);

            Class.forName("org.h2.Driver");
            Connection conn = DriverManager.getConnection("jdbc:h2:~/test");
            Statement stat = conn.createStatement();

            // this line would initialize the database
            // from the SQL script file 'init.sql'
            // stat.execute("runscript from 'init.sql'");

            stat.execute("create table test(id int primary key, name varchar(255))");
            stat.execute("insert into test values(1, 'Hello')");
            ResultSet rs;
            rs = stat.executeQuery("select * from test");
            while (rs.next()) {
                System.out.println(rs.getString("name"));
            }
            conn.close();
        }

    }

     

  • 相关阅读:
    oracle连接本地数据库
    ERWin 7.2下载安装及注册机
    关于oracle中to_char和to_date的用法
    2016年11月26号随笔(关于oracle数据库)
    SQL Server Browser服务的作用
    正则表达式
    server重启导致执行包的job运行失败
    Windows Log和SQL SERVER errorlog
    windows services创建和部署
    c# 读取App.config
  • 原文地址:https://www.cnblogs.com/likwo/p/1755564.html
Copyright © 2011-2022 走看看