Load Drive method1.class.forname ("Com.microsoft.sqlserver.jdbc.SQLServerDriver");2. Drivermanager.registerdriver (New Com.mysql.jdbc.Driver ());3.system.setproperty ("Jdbc.drivers", "Com.mysql.jdbc.Driver"); JDBC Process:
- Load the drive DriverManager. Registerdriver (Driver Driver)
- Get connection Connection conn = drivermanager.getconnection (Url,user,pass);
- Create Statement Statement st = Conn.createstatement () by connection;
- Parse SQL get result set ResultSet rs = st.excutequery (SQL);
- Traverse result set, get Data Rs.getobject (XX)
- Freeing resources, closing connections
- 1. Load the JDBC driver:
- before connecting to the database, first load the driver of the database you want to connect to the JVM (Java Virtual machine),
- This is achieved through the static method forname (String className) of the Java.lang.Class class.
- 2 Creating a connection to a database
- To connect to a database, you need to request and obtain a connection object from Java.sql.DriverManager.
- The object represents a connection to a database.
- ? Using the DriverManager getconnectin (string URL, string username,
- String password) method to pass in the path to the specified database to be connected, the user name of the database, and
- Password to get it.
Methods for loading database drivers and the process of JDBC