Java Database Programming and Java XML parsing technology, database programming xml

Source: Internet
Author: User

Java Database Programming and Java XML parsing technology, database programming xml
1. JDBC Overview

A. What is JDBC?

Java DataBase Connectivity: a Java API used to execute SQL statements. It consists of a group of classes and interfaces written in Java. Through these classes and interfaces, JDBC sends SQL statements to different types of databases for processing and receives processing results.

B. Common JDBC classes and interfaces: DriverManager class, Connection interface, Statement interface, PreparedStatement interface, and ResultSet Interface

2. JDBC programming steps

1). Load the driver

Class. forName ("");

2) create a Connection object

Connection c = DriverManager. getConnection ("path", "username", "password ");

3). Create a declaration statement object using the connection object

Statement s = c. createStatement ();

4). operate or query data

5) Close various objects

3. Understand four JDBC drivers

JDBC-ODBC Bridge: JDBC-ODBC Bridge

SUN provides a general-purpose driver to access a variety of databases, but the efficiency is extremely low.

B. Native-API partly-Java driver: local library Java driver

High execution efficiency. Local drivers must be installed on the client, which is inconvenient for maintenance.

C. net-protocal all-Java driver (JDBC Proxy): network protocol pure Java driver (General)

The client does not have to install a local database, which is easy to use but has relatively low performance.

D. native-protocal all-Java driver: Local protocol full Java driver

It is highly efficient to convert JDBC calls to the network protocol of a specific database.

4. Manage result sets

A. Why use the result set?

The result set needs to be moved and processed repeatedly.

It is another way for JDBC to process data sets as objects.

B. What is a result set? A result set is an object mapped to a database, such as a table.

C. Classification of result sets

Scrollable result set

Updatable result set

5. XML Overview

A. What is XML?

XML (extended Markup Language): Extensible Markup Language

6. XML syntax rules

A. XML Declaration

A. XML declaration is generally the first line of the XML document.

B. XML Declaration consists of the following parts:

Version: The document complies with the XML1.0 specification. Currently, only 1.0 is supported.

Encoding: document character encoding; default: "UTF-8"

Standalone: whether the file is defined in a file

(Standalone = "yes", standalone = "no ")

For example: <? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"?>

B. XML comment: <! -- This is a comment -->

Note: do not appear in the comment content, do not place the comment in the middle of the mark, the Comment cannot be nested, you can place the comment in any place except the mark.

C. XML processing commands

A. The processing command is used by the XML parser to transmit information to the application.

B. Format: <? Processing Command name Processing Command Information?>

<? Xml: stylesheet type = "text/xsl" href = "example. xsl"?>

D. XML Element

A. Relationship between elements: child element/parent element, ancestor/descendant

Element content type: Nested element/character data/entity reference/CDATA section/Processing Instruction/comment

B. XML root element: each XML document must have only one root element. The root element is an element that fully includes all other elements in the document. The start tag of the root element should be placed before the start tag of all other elements, the end mark of the root element should be placed after the end mark of all other elements.

C. XML Entity

& Lt: <

& Gt:>

& Amp :&

& Quot :"

& Apos :'

D. Naming rules for XML Element tags:

1). the name can contain letters, numbers, or other characters

2). The name cannot start with a number or underscore (_).

3). Cannot use XML/xml/Xml /... Start

4). The name cannot contain spaces.

5). The name cannot contain colons (Note: colons are reserved for namespaces)

E. CDATA: used to interpret the entire text segment as pure character data rather than markup. Contains a large number of <,>, &, or "characters. All characters in the CDATA section are treated as constants of the element character data, rather than XML tags.

Note: CDATA is text not parsed by the parser. Labels in text are not marked, and objects are not expanded.

Syntax:

<! [CDATA [

........

]>

F. XML Element attributes: attribute values are separated by double quotation marks (") or single quotation marks ('). If the attribute values contain', use" to separate them; if yes ", use" to separate them)

An element can have multiple attributes. Its basic format is:

<Element name property name = "attribute value">

The specified attribute name can only appear once in the same element tag.

Attribute values cannot include <,> ,&

7. XML Technical System Overview

A. Document Description and validation technology: Both DTD and Schema are used to define XML structures and verify whether the XML documents we write meet the requirements.

B. Document Conversion Technology (XSL/XSLT)

C. Document Query Technology (XPath/XQuery)

D. Document parsing Technology (xml dom/SAX)

E. Document link and positioning technology (XLink/XPointer)

8. XML parsing Technology

A. Document Object Model (DOM), A tree structure-based API

B. XML Simple API (SAX), an event-driven implementation of APIC. DOM and SAX parsing techniques a. JAXP (Java API for XML) B. JDOM c. DOM4J:

Common Resolution Methods

SAXReader saxReader = new SAXReader ();

Document document = saxReader. read (inputFile );

SelectNodes ()

GetValue ()

ElementIterator ()

 

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.