package com.derby.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class DerbyTest {
public static void main(String[] args) throws Exception{
Connection connection = null;
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
connection = DriverManager.getConnection("jdbc:derby:dy;create=true");
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.
// statement.executeUpdate("drop table if exists person ");
statement.executeUpdate("drop table person ");
statement.executeUpdate("create table person (id integer, name varchar(50))");
statement.executeUpdate("insert into person values(1, '我是第一个学生')");
statement.executeUpdate("insert into person values(2, '中国人')");
statement.executeUpdate("insert into person values(45, '外国人')");
statement.executeUpdate("insert into person values(4, '中国人')");
ResultSet rs = statement.executeQuery("select * from person order by name ");
while(rs.next()){
System.out.println("id: "+rs.getInt("id")+" name: " + rs.getString("name"));
}
rs.close();
statement.close();
connection.close();
}
}
(2)hsqldb的使用:
package com.hsqldb.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class HSQLdbTest {
public static void main(String[] args) throws Exception{
Connection connection = null;
Class.forName("org.hsqldb.jdbcDriver");
//内存计算
connection = DriverManager.getConnection("jdbc:hsqldb:mem");
//支持持久存储
//connection = DriverManager.getConnection("jdbc:hsqldb:file:hsql.db");
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.
statement.executeUpdate("drop table if exists person ");
//statement.executeUpdate("drop table person ");
statement.executeUpdate("create table person (id integer, name varchar(50))");
statement.executeUpdate("insert into person values(1, '我是第一个学生')");
statement.executeUpdate("insert into person values(2, '中国人')");
statement.executeUpdate("insert into person values(45, '外国人')");
statement.executeUpdate("insert into person values(4, '中国人')");
ResultSet rs = statement.executeQuery("select * from person order by id ");
while(rs.next()){
System.out.println("id: "+rs.getInt("id")+" name: " + rs.getString("name"));
}
rs.close();
statement.close();
connection.close();
}
}
(3)h2的使用:
package com.h2.test;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
public class H2Test {
public static void main(String[] args) throws Exception{
Connection connection = null;
Class.forName("org.h2.Driver");
//内存计算
connection = DriverManager.getConnection("jdbc:h2:mem:");
//支持持久存储
//connection = DriverManager.getConnection("jdbc:h2:file:./bb.bb");
//connection = DriverManager.getConnection("jdbc:h2:./bb.bb");
Statement statement = connection.createStatement();
statement.setQueryTimeout(30); // set timeout to 30 sec.
statement.executeUpdate("drop table if exists person ");
//statement.executeUpdate("drop table person ");
statement.executeUpdate("create table person (id integer, name varchar(50))");
statement.executeUpdate("insert into person values(1, '我是第一个学生')");
statement.executeUpdate("insert into person values(2, '中国人')");
statement.executeUpdate("insert into person values(45, '外国人')");
statement.executeUpdate("insert into person values(4, '中国人')");
ResultSet rs = statement.executeQuery("select * from person order by id ");
while(rs.next()){
System.out.println("id: "+rs.getInt("id")+" name: " + rs.getString("name"));
}
rs.close();
statement.close();
connection.close();
}
}
其中h2和hsqldb是非常类似的,但是又有很大的不同,通过下面的一张对比表,我们可以看出来他们之间有什么不同之处:
其实,散仙做这些对比,也是为了了解一下他们不同之处,使用内存库,用来统计一些不需要持久化操作的数据,而且数量不大的数据,是非常方便的。
大小: 463.1 KB
下载次数: 25
分享到:
2014-10-13 17:51
浏览 2101
论坛回复 / 浏览 (0 / 1669)
评论