Java Learning Notes-the 13th chapter introduction to database Programming

Source: Internet
Author: User

13th. Getting Started with database programming

  1. Understanding JDBC

    Access to the database in Java is primarily done through JDBC. JDBC is the abbreviation for Java Database connection technology (Java DB Connectivity), an API for executing SQL statements that provides unified access to a variety of relational databases. Consists of a set of classes and interfaces written in the Java language. (SQL is the abbreviation for Structure Query language, meaning Structured Query language, which is a standard relational database access language.) )

  2. The working mechanism of JDBC

    Using JDBC to complete access to the database consists of the following five levels: Java application, jdbc API, JDBC driver, DBMS, and database.


    650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/8E/wKioL1VMWW3gTD8cAACC1V07dtE004.jpg "title=" Untitled. png "alt=" wkiol1vmww3gtd8caacc1v07dte004.jpg "/>

    The DBMS (Database management System) is the abbreviation for the databases Management system and is a large software that operates and manages databases for the establishment, use, and maintenance of databases. For example, MS SQL, Access, Oracle, Visual FoxPro, and so on are all part of the DBMS. DBMS can manage and control the database uniformly to ensure the security and integrity of the database. Users can access the data in the database through the DBMS, and the database administrator can maintain the database through the DBMS.

    To access a database, Java applications should first load the JDBC driver for the specific database type with the JDBC API, and then access the various databases with the JDBC API. In short, JDBC can do three things: ① loads the JDBC driver and creates a database connection, ② sends the statement of the operational database to the DBMS and lets the DBMS execute it; ③ processes the returned results.

    String MSODBC = "Sun.jdbc.odbc.JdbcOdbcDriver";

    Class.forName (MSODBC); Load Driver

    String url = "Jdbc:odbc:javaodbc";

    Connection conn = drivermanager.getconnection (URL); Establish a connection

    Statement st = Conn.createstatement (); Create a statement object

    St.executequery ("Select a,b,c from table"); Call the ExecuteQuery () method of the Statement object

  3. JDBC URL parameter

    The JDBC URL provides a way to identify the database so that the appropriate driver can identify and establish a connection to the database. The standard format for a JDBC URL consists of three parts, separated by colons, as follows:

    jdbc:< Sub-Protocol >:< sub-name >

    The meanings are as follows:

    The protocol in the JDBC:JDBC URL is always JDBC.

    < sub-Protocol;: Name of the driver name or database connection mechanism (this mechanism can be supported by one or more drivers). A typical example of a sub-protocol is ODBC, which indicates that JDBC is using the Jdbc-odbc bridge driver.

    < database sub-name;: Typically, the name of the database, which must provide sufficient information for the location database.

  4. Database operations

    (1) Add record: INSERT into table name (field list) VALUES (Value list)

    (2) Delete record: Delete form table name where condition

    (3) Modify record: Update table name set field name = value WHERE condition

    (4) Query record: Selete field 1, Field 2, Field 3,... from table name where condition

Java Learning Notes-the 13th chapter introduction to database Programming

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.