Implementing Web servers that support video-on-demand using the Java language (2)

Source: Internet
Author: User
Tags driver manager connect odbc query access database linux
Web|web Service |web server Access database, because this project is a small community-oriented Community Data Center server, so choose a small database. Because Java portability can use the server on a Linux platform, you can use the database configuration program provided by this server to connect to a small Linux based database such as MySQL. JDBC completes the connection to the database. One of the great capabilities of Java is to build platform-independent client/server database applications. In Java 1.1, the interconnection of databases with each company is achieved through a Java database connection (JDBC). One of the main problems with the database is the size wars between companies. There is indeed a "standard" database language, the "Structured Query Language" (SQL-92), but companies have some minor changes to their standards to express their differences. So it's usually important to know exactly which database company you want to deal with, or it's very easy to go wrong, despite the so-called "standard". JDBC is geared toward "platform-independent" design, so you don't have to be concerned about what database product you're using when you're programming. As with many of the APIs in Java, JDBC has been simplified as much as possible. The method call we emit corresponds to what is taken for granted when data is collected from the database: Connect to the database, create a statement and execute the query, and then process the result set, regardless of which database manufacturer's product we are dealing with. "Platform-Independent" features, JDBC provides us with a "driver manager" that dynamically maintains all the driver objects required for database queries. So if you want to connect to different kinds of databases developed by several companies, you need a separate driver object for each database. The driver object is automatically registered by the Driver manager at load time and can be forcibly loaded with Class.forName (). To open a database, you must create a "database URL" that specifies three things: (1) using JDBC to indicate that you want to use it. (2) "Sub-Protocol": The name of the driver or the name of a database connection mechanism. Since the design of JDBC absorbs a lot of inspiration from ODBC, the first seed protocol that can be chosen is the "Jdbc-odbc Bridge", which is specified with the "ODBC" keyword. (3) Database identifiers: Vary with the database drivers used, but generally provide a more logical name, mapped by the database management software to a physical directory that holds the datasheet. In order to have any meaning to your database identifier, you must register with your own database management software for your favorite name (the specific process of registration varies with the operating platform). All this information is compiled uniformly into a string, the database URL. In this case, we want to use the ODBC Sub-Protocol to the same identityFor the "VOD" database connection, the corresponding database URL is set to: Similarly, if a network connection is used, the database URL also needs to contain information that identifies the remote machine. First, the database database driver is registered in DriverManager in JDBC. JDBC-ODBC Bridge driver, so that DriverManager can find the database driver. Then use DriverManager to open the connection to the database. The purpose of this statement is to determine the connection to the database specified by Dburl. DriverManager will look for the most appropriate driver from the driver registered in it. The returned mycon represents a connection to a particular database. The statement interface for the SQL statement. You can then use the ExecuteQuery () function to execute the SQL statement in Mysta to get the execution result from the returned resultset.

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.