The use of Java has been more than two years and has never been a study in depth specific things, has been used in any job, and then learn what seems to understand everything that is啥都do not know. Thus, there is this idea, in-depth study of a framework, not only to master the application, and understand the principles of martial arts novels in Enhancing similar strength, with strength for the deep foundation, the tactic of the new study, one-click. Have a mind that, through my blog, allow themselves to learn and upgrade.

Java open-source world, there is a lot of excellent framework, the latest in the use of hibernate, so to study the selection hibernate.

Hibernate is a framework and object mapping (ORM), which is based on JDBC, beginning from the most basic study from JDBC. Here is a simple write my own DEMO:



        // 注册加载jdbc驱动
     Class.forName("org.hsqldb.jdbcDriver").newInstance();

        // 创建一个到数据库的连接
     Connection conn = DriverManager.getConnection(
            "jdbc:hsqldb:hsql://localhost", "sa", "");

        // 创建一个statement
        Statement statement = conn.createStatement();

        // 使用statement对象执行SQL语句
     statement.execute("select * from events");

        // 处理结果集:打印所有行数据
     ResultSet rs = statement.getResultSet();
       while (rs.next()) {
            System.out.println("ID:" + rs.getInt(1) + " TITLE:"
                    + rs.getString(2) + " DATE:" + rs.getDate(3));

        }

        // 释放jdbc相关对象资源
     rs.close();
       statement.close();
       conn.close();






These are the most simple JDBC application, all the JDBC application that will have some of the same steps:

  1. Register a JDBC driver (using the reflection of a dynamically loaded driver examples)
  2. Set up a connection to the database (the application to interact with the database must first establish a connection)
  3. Create a statement object (as the English meaning of the statement: statement, this is a SQL statement for the implementation of the object)
  4. Use statement object to implement SQL statements (such as inquiries, select)
  5. Statements deal with the results of the implementation of (ResultSet type of object used to store the query result set, the object can handle the result set)
  6. JDBC release the subject of the use of the resources (database of expensive resources are limited, we use after the release of those resources to other applications to use)