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;

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

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

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools