JDBC study notes_PHP tutorial
l. Method of connecting to the database
Answer: 1) ODBC (Open Database Connectivity)
An interface based on C language to access SQL-based database engine. It provides a consistent interface for and Database communication and access to data.
2) JDBC
Java version of ODBC
2. JDBC application programming interface
Answer: The JDBC application programming interface is:
1) Standard data access interface that can be connected to Different databases;
2) A set of classes and interfaces in the JAVA programming language.
JDBC application programming interface can:
1) Connect to the database;
2) Send SQL query string to the database;
3) Process the results.
The JDBC application programming interface has two main parts:
1) JAVA application development interface for JAVA application developers;
2) JDBC driver development interface
3. JDBC Driver
Answer: 1) A large number of classes that implement JDBC classes and interfaces;
2) Provides a class that implements the java.sql.Driver interface.
4. Four types of JDBC Driver
Answer: 1) JDBC-ODBC Bridge
JDBC access is provided by the ODBC driver
2) Local API
Some Java drivers call JDBC Convert to local client API
3) JDBC-net
A pure Java driver that transfers JDBC calls to DBMS and has nothing to do with network protocols. The call is then converted to the DBMS protocol through the server.
4) Local protocol
Pure java driver, converts JDBC calls directly into the network protocol used by DBMS
5. JDBC developer interface
Answer: 1) java.sql-- The main functions of JDBC under the Java 2 platform, Standard Edition (J2SE)
2) javax.sql--JDBC enhanced functions under the Java 2 platform, Enterprise Edition (J2EE)
6. Confirm the database using URL
A: We use URL to determine a database (correct Driver, correct host, correct protocol, correct protocol, correct username and password);
Syntax: protocol:subprotocol:subname
Example: jdbc:db2:MyTest
jdbc:db2://localhost:6789/MyTest
7. Enhanced functions of javax.sql package JDBC2.0
Answer: 1) Data source interface;
2) Connection pool;
3) Distributed transaction;
4) Rowset;
8. Create a basic JDBC application
Answer: 1) Step 1: Register a driver ;
2) Step 2: Establish a connection to the database;
3) Step 3: Create a statement;
4) Step 4: Execute the SQL statement;
5) Step 5: Process the results ;
6) Step 6: Close the JDBC object
9. Register a Driver (Step 1)
Answer: 1) The driver is used to connect to the database;
2) JDBC application programming The interface uses the first driver that can successfully connect to the given URL;
3) Multiple drivers can be loaded at the same time
10. How to register a driver:
Answer: 1) Use Class loader (loading; instantiation; registration into DriverManager)
a. Class.forName("Com.ibm.db2.jdbc.app.DB2Driver");
b. Class.forName("Com.ibm. db2.jdbc.net.DB2Driver");
c. Class.forName("Com.microsoft.jdbc.sqlServer.SQLServerDriver);
d. Class.forName("oracl.jdbc.driver.OracleDriver") ;
e. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
2) Instantiate a Driver
a. Driver drv = new COM.cloudscape.core.RmiJdbcDriver();
1. Establish a connection to the database (step 2)
Answer: DriverManager calls the getConnection(urlString) method, which actually calls the driver’s connect(urlString) method;
1) When a The driver definitely corresponds to a database URL, and the DriverManager establishes a connection;
2) When no driver matches, null is returned and the next driver is checked;
3) If the connection is not established, a SQLExcepiton exception is thrown
2. Some commonly used JDBC URLs
Answer: 1) JDBC-ODBC: jdbc:odbc:
2) Oracle: jdbc:oracle:oci:@
3) Weblogic MS-SQL: jdbc:weblogic:mssqlserver4:
4) DB2: jdbc: db2:MyTest or jdbc.db2://localhost:6789/MyTest (requires username and password)
3. Driver connection method
Answer: 1) Create a direct call to the specified Driver instance;
2) Avoid general access problems
Driver drv = new COM.ibm.db2.jdbc.app.DB2Driver();
Connection con = null;
try {con = drv.connect(" jdbc:db2:MyTest",new Properties())}
catch(SQLException e){}
4. Create a Statement (step three)
Answer: 1) Three interfaces of Statement :
a. Statement;
b. PreparedStatement (inherited from Statement);
c. CallableStatement (inherited from PreparedStatement);
2) Use the method Connection.createStatement() to get a Statement object
5. PreparedStatement object
Answer: 1) Calling ProparedStatement is more efficient than statement;
2) Inherited from Statement;
3) Syntax: PreparedStatement pstm = connection.prepareStatement(sqlString);
6. CallableStatement object
Answer: 1) Call the stored procedure in the database through CallableStatement;
2) Inherited from PreparedStatement;
3) CallableStatement cstm = connection.prepareCall("{call return_student [?,?]}");
cstm.setString(1,"8623034");
cstm.registerOutparameter(2, Types.REAL);
cstm.execute();
float gpa = cstm.getFloat( 2);
7. Comparison of Statement interfaces
Answer: -------------------------------------------------- -------
Code writing location | Client | Client | Server side
-------------------------- -------------------------------------------------- ---
Code writing location | Client | Server side | Server side
-------------------------------- --------------------------------------------------
Coding technology | Java, SQL operations | Java, SQL operations | Database programming language, such as PL/SQL
-------------------------- -------------------------------------------------- ------
Configurability | High | High for the first time, low thereafter | Low
----------------------- -------------------------------------------------- -----
Portability | High | High if PreparedStatement is supported
--------------------------- --------------------------------------------------
Transmission efficiency | Low | Low for the first time, high thereafter | High
8. Execute SQL Statement (Step 4)
Answer: Transmit the SQL statement to the recognized database connection through the interface method , the returned result may be a data table, which can be accessed through java.sql.ResultSet.
1) Statement interface method:
a. executeQuery(sqlString): Execute the given SQL statement and return a result set (ResultSet) object;
b. executeUpdate(sqlString): Execute the given SQL statement, which can be an INSERT, UPDATE or DELETE statement, or a SQL DDL statement;
c. execute(sqlString): Execute the given SQL statement.
9. Processing results (step 5)
Answer: 1) Use the access method of the ResultSet object to obtain data;
a. next(): next record
b . first(): the first record
c. last(): the last record
d. previous(): the previous record
2) Obtain data through field name or index
3) The result set maintains a pointer to the current row, initialized before the first record.
10. Close the JDBC object (step 6)
Answer: 1) First close the record set;
2) Secondly close the statement;
3) Finally close the connection object.
11. Three relationships between data tables and classes:
Answer: 1) One table corresponds to one class;
2) One table corresponds to related classes;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

IntelArrowLakeisexpectedtobebasedonthesameprocessorarchitectureasLunarLake,meaningthatIntel'sbrandnewLionCoveperformancecoreswillbecombinedwiththeeconomicalSkymontefficiencycores.WhileLunarLakeisonlyavailableasava

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.
