JDBC study NOTE _ PHP Tutorial

Source: Internet
Author: User
JDBC study notes. L. how to connect to the database answer: 1) ODBC (OpenDatabaseConnectivity) an interface for accessing the SQL-based database engine in C language. It provides consistent interfaces for data and numbers. how to connect to the database
Answer: 1) ODBC (Open Database Connectivity)
An interface that uses C language as the basis for accessing the SQL database engine. It provides consistent interfaces for communicating with the database and accessing data.
2) JDBC
Java ODBC

2. JDBC application programming interface
A: The JDBC application programming interface is:
1) Standard data access interfaces can be connected to different databases;
2) a group of classes and interfaces in the JAVA programming language.
JDBC application programming interface:
1) connect to the database;
2) Send an SQL query string to the database;
3) processing result.
The JDBC application programming interface has two main parts:
1) the JAVA application development interface is intended for JAVA application developers;
2) JDBC driver development interface

3. JDBC Driver
Answer: 1) a lot of classes that implement JDBC classes and interfaces;
2) provides a class to implement the java. SQL. Driver interface.

4. four JDBC Driver types
A: 1) JDBC-ODBC Bridge
JDBC access provided by ODBC driver
2) local API
Some Java drivers convert JDBC calls to client APIs
3) JDBC-net
A pure Java driver transfers JDBC calls to DBMS, regardless of the network protocol. Then, the server converts the call to the DBMS protocol.
4) local protocol
Pure java driver converts JDBC calls directly to the network protocol used by DBMS

5. JDBC developer interface
Answer: 1) java. SQL: main functions of JDBC on the java 2 Platform, Standard Edition (J2SE)
2) javax. SQL -- JDBC enhancements on the java 2 Platform, Enterprise Edition (J2EE)

6. use URL to confirm the database
A: We use the URL to determine a database (correct Driver, correct host, correct protocol, correct protocol, correct user name and password );
Syntax: protocol: subprotocol: subname
Example: jdbc: db2: MyTest
Jdbc: db2: // localhost: 6789/MyTest

7. enhanced functions of the javax. SQL package JDBC2.0
Answer: 1) Data source interface;
2) connection pool;
3) distributed transactions;
4) row set;

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 result;
6) Step 6: disable the JDBC object

9. Register a Driver (step 1)
Answer: 1) the driver is used to connect to the database;
2) the JDBC application programming interface uses the first driver that can successfully connect to a given URL;
3) multiple drivers can be loaded at the same time.

10. how to register a driver:
Answer: 1) use a class loader (load; instantiate; register with 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 ("CMDL. 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)
A: DriverManager calls the getConnection (urlString) method. actually, it calls the connect (urlString) method of the driver;
1) when a driver definitely maps to a database URL, DriverManager establishes a connection;
2) if no driver matches, null is returned and the next driver is verified;
3) if no connection is established, an SQLExcepiton exception is thrown.

2. frequently used JDBC URLs
A: 1) JDBC-ODBC: jdbc: odbc:
2) Oracle: jdbc: oracle: oci :@ Or jdbc: oracle: thin :@
3) Weblogic MS-SQL: jdbc: weblogic: mssqlserver4: @ :
4) DB2: jdbc: db2: MyTest or jdbc. db2: // localhost: 6789/MyTest (username and password required)

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 3)
Answer: 1) Three Statement interfaces:
A. Statement;
B. PreparedStatement (inherited from Statement );
C. CallableStatement (inherited from PreparedStatement );
2) use 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 );
Ccmd.exe cute ();
Float gpa = cstm. getFloat (2 );

7. Comparison of Statement interfaces
Answer: | Statement | PreparedStatement | CallableStatement
------------------------------------------------------------------------------
Code writing location | client | server
------------------------------------------------------------------------------
Code writing location | client | server
------------------------------------------------------------------------------
Coding technology | Java and SQL operations | database programming languages, such as PL/SQL
------------------------------------------------------------------------------
Configurable | high for the first time, low for the future | low
------------------------------------------------------------------------------
Portability | high if PreparedStatement is supported
------------------------------------------------------------------------------
Transmission efficiency | low for the first time, high for the future | high

8. execute SQL Statement (step 4)
A: The interface method is used to transmit the SQL statement to the database connection recognized by the hacker. the returned result may be a data table that can be accessed through java. SQL. ResultSet.
1) Statement interface method:
A. executeQuery (sqlString): executes the given SQL statement and returns a result set object;
B. executeUpdate (sqlString): execute the given SQL statement, which can be an INSERT, UPDATE, or DELETE statement or an SQL DDL statement;
C. execute (sqlString): execute the given SQL statement.

9. processing result (step 5)
Answer: 1) use the access method of the result set object to obtain data;
A. next (): next Record
B. first (): The first record
C. last (): The last record
D. previous (): previous record
2) obtain data by field name or index
3) the result set maintains a pointer pointing to the forward direction. the initialization position is before the first record.

10. disable the JDBC object (step 6)
Answer: 1) first, disable the record set;
2) close the statement;
3) close the connection object.

11. three relationships between data tables and classes:
Answer: 1) a table corresponds to a class;
2) a table corresponds to a related class;

Http://www.bkjia.com/PHPjc/508517.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/508517.htmlTechArticlel. how to connect to the Database answer: 1) ODBC (Open Database Connectivity) an interface for accessing the SQL-based Database engine in C language. It provides consistent interfaces for data and data...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.