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:
- Register a JDBC driver (using the reflection of a dynamically loaded driver examples)
- Set up a connection to the database (the application to interact with the database must first establish a connection)
- Create a statement object (as the English meaning of the statement: statement, this is a SQL statement for the implementation of the object)
- Use statement object to implement SQL statements (such as inquiries, select)
- 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)
- 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)







