JDBC Review-orm specification
JDBC Operation steps
- Registering Database Drivers
Class.forName ("Jdbcdriverclass")
Database |
Driver Class |
Source |
Access |
Sun.jdbc.odbc.JdbcOdbcDriver |
In the JDK |
Mysql |
Com.mysql.jdbc.Driver |
Download MySQL Driver pack |
Oracle |
Oracle.jdbc.driver.OracleDriver |
Download the corresponding driver package |
SQL Server |
Com.microsoft.sqlserver.jdbc.SQLServerDriver |
Download the corresponding driver package |
In order to use the driver package, you need to add the downloaded driver package to the CLASSPATH
- Create a connection type Object
Connection Connection = drivermanager.getconnection (Databaseurl,username,password);
Access does not require the Username,password parameter
Database |
URL pattern |
Access |
Jdbc:odbc:dataSource |
Mysql |
Jdbc:mysql://hostname/dbname |
Oracle |
Jdbc:oracle:thin: @hostname:p Ort#:oracledbsid (port# represents the port number, ORACLEDBSID is the database name of the location database) |
SQL Server |
Jdbc:sqlserver://hostname:port;databasename= database name |
Get Statement type Object
Statement Statement = Connection.createstatement ()
Perform a query or update
You can use Executeupdate () to execute SQL DDL (data definition Language) or UPDATE statements
Query statements can be executed using executequery ()
Working with ResultSet type objects
Query results exist in resultset, you can use next () to move the cursor to the next line, using getxxx (XXX for data type) to get the column values of the current row
Freeing resources
Connection.close ()
Orm
全称Object/Relation Mapping,对象/关系映射 ORM框架:完成面向对象的程序设计语言到关系数据库的映射 目前的产品很多,如:Apache组织下的OJB,Oracle的TopLink,JDO,JPA等 优点:提高生产效率,可维护性
One of the Hibernate learning notes (JDBC Review-orm specification)