7/9/13

H2 Database

Hello folks,

I was asked to do some encryption using java for some of the files that i create inside the product . I has a thought about using some in memory database and then dropped at "H2" , H2 seems to be promising and offers wide variety of solutions. You can use it as an embedded db, in memory db and also make it as server-client mode. The notable factor is performance that is offered in H2, seems it is at least twice than the rest.

Please refer the following URL to know more about H2 : http://www.h2database.com/html/main.html

Simple Example in Java : 

import java.sql.*;
public class SampleHTwo {

    public static void main(String[] args) {
        Connection connection = null;
        ResultSet resultSet = null;
        Statement statement = null;
        try {
            Class.forName("org.h2.Driver");
            connection = DriverManager.getConnection("jdbc:h2:E:\\H2DB/test1;AUTO_SERVER=TRUE");
            statement = connection.createStatement();
            statement.execute("CREATE CACHED TABLE student(id INT PRIMARY KEY, name VARCHAR(255))");
           statement.execute("insert into student(id,name) values(2,'raghu')");
            resultSet = statement.executeQuery("SELECT name FROM student");
            while (resultSet.next()) {
                System.out.println("student NAME:" + resultSet.getString("name"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

 

No comments:

Post a Comment

Popular Posts