What interfaces does JDBC have

1 The object that implements the Driver interface is the beginning of JDBC database access, and the driver can be dynamically loaded through the forName() of the java.lang.Class class.

Class.forName("driver");

2 The implementation object of the Connection interface is the representative object of the database connection. To get the Connection implementation object, you can use the getConnection() method of the DriverManager (driver management class).

Connection conn=DriverManager.getConnection(jdbcUrl,user,password); //Number of address, username, password of database connection object

3 Using Statement and ResultSet, if the connection object conn is obtained, then to execute the SQL statement, the SQL.lang.Statement object must be obtained, the representative object of the sql statement.

.Statement  statement=conn.createStatement();

You can use executeUpdate(), executeQurey(), execute() and other methods to execute SQL statements.

The int result returned by executeUpdate() represents the number of data changes.

executeQurey() will return the java.lang.ResultSet result set object to save the results of the query. You can use the ResultSet's pointer to move to the next data.

4 PreparedStatement interface: Represents the precompiled SQL statement object. The SQL statement is precompiled and stored in the PreparedStatement object. Before executing the SQL statement, the parameters are dynamically set, and the statement can be executed multiple times efficiently.

5 SQLException is an exception object when dealing with JDBC, and it represents the object when an error occurs during database operation. is a checked exception and must be handled explicitly using try...catch.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324746638&siteId=291194637