mysql中使用h2_H2数据库的使用

Database

URLs

jdbc:h2:~/test 'test' in the user home

directory

jdbc:h2:/data/test 'test' in the directory

/data

jdbc:h2:test in the current(!) working

directory

jdbc:h2:mem:test multiple connections in

one process

jdbc:h2:mem: unnamed private; one

connection

jdbc:h2:tcp://localhost/~/test user home

dir

jdbc:h2:tcp://localhost//data/test absolute

dir

Server

start:java

-cp *.jar org.h2.tools.Server

jdbc:h2:..;MODE=MySQLcompatibility

(or HSQLDB,...)

jdbc:h2:..;TRACE_LEVEL_FILE=3log

to *.trace.db

测试代码:

package

cc;

import

java.sql.*;

public class

TestH2 {

public static

void main(String[] args) throws Exception {

Class.forName("org.h2.Driver");

//embedded

file

//Connection

conn = DriverManager.getConnection("jdbc:h2:~/testh2",

"sa","");

//embedded

mem

Connection conn

= DriverManager.getConnection("jdbc:h2:mem:",

"sa","");

System.out.println(conn);

createTable(conn);

insert(conn);

select(conn);

}

private static

void select(Connection conn) throws Exception {

String sql =

"Select ID, CONFIG_KEY, CONFIG_VALUE From

art_config";

ResultSet rs =

conn.createStatement().executeQuery(sql);

while(rs.next())

{

System.out.println(rs.getString(1) + ", " +

rs.getString(2) + ", " + rs.getString(3));

}

}

private static

void insert(Connection conn) throws Exception {

String sql

=

"insert into

art_config (ID, CONFIG_KEY, CONFIG_VALUE, REMARK) "

+

" values (2,

'quartzServerIps', '172.21.127.29', null)";

int i =

conn.createStatement().executeUpdate(sql);

System.out.println(i);

}

private static

void createTable(Connection conn) throws Exception

{

String sql

=

"create table

ART_CONFIG\n" +

"(\n"

+

"

id  NUMBER(19)

not null,\n" +

"

config_key  VARCHAR2(50) not

null,\n" +

"

config_value VARCHAR2(4000),\n"

+

"

remark  VARCHAR2(500)\n"

+

")";

conn.createStatement().execute(sql);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值