How to connect in db practice

Source: Internet
Author: User
Tags connection pooling wrapper

Today, test how Java DB is connected.

There are two types of knowledge that I know at the moment:

      1. JDBC Code Links

      2. DataSource Links

Let's look at the two ways to connect in more detail below

The first JDBC connection, which we need to know about Java's related class Javax.sql class

Package Javax.sql

Provides APIs for server-side data source access and processing through the Java programming language

Interface Summary

Commondatasource This interface defines a common method between DataSource, Xadatasource, and Connectionpolldatasource

1. All sub-interfaces ConnectionPoolDataSource DataSource Xadatasource

2. Summary of methods

A. int getlogintimeout () Gets the maximum amount of time, in seconds, that this data source can wait to connect to a database

B.printwriter Getlogwriter () gets this DataSource object log write.

C.void setlogintimeout (int seconds) sets the maximum time, in seconds, that this data source will wait when attempting to connect to a database

D. Setlogwriter (PrintWriter out) sets the log writer for this DataSource object to the given Java.io.PrintWriter

The above is the method of the Super interface Commondatasource, and the known sub-interface

Here's a three sub-interface.

  1. ConnectionPoolDataSource

    1. Pooledconnection Object Factory

    2. Method is inherited by the parent class Commondatasource method Getlogintimeout setlogintimeout Setlogwriter Getlogwriter, its own methods are:

      1. Pooledconnection getpooledconnection () attempts to establish a physical database connection that can be used as pooled connection

      2. Pooledconnection getpooledconnection (String usr,string Password) attempts to establish a physical database connection that can be used as a pooled connection

  2. Interface DataSource

    1. DataSource This interface not only inherits the Commondatasource but also inherits the wrapper

    2. The factory is used to provide a connection to the physical data source represented by this DataSource object. As an alternative to the DriverManager tool, the DataSource object is the preferred method for getting a connection. Objects that implement the DataSource interface are typically registered in a naming service that is based on the Java naming and Directory Interface (JNDI) API.

    3. The
    4. DataSource interface is implemented by the driver vendor. A total of three types are implemented:

      1. Basic implementation-Generate standard connection objects

      2. Connection pool Implementation-Generate auto-ginseng Jade The connection object for the connection pool, which is implemented with the middle-tier connection pool manager using the

      3. Distributed transaction Implementation-generates an connection object that can be used for distributed transactions, and in most cases is always involved in connection pooling. This implementation is used with the middle-tier transaction manager and is always used with the connection pool manager in most cases. The properties of the

      4. DataSource object can be modified when necessary. GCA, if you move the data source to another server, you can change the properties that are related to the server. The advantage is that because you can change the properties of the data source, any code that accesses the data source does not have to change the driver that

      5. Accesses through the DataSource object itself and does not register with DriverManager The DataSource object is obtained by a find operation, and then using the object to create the connection object using the basic implementation, the connection obtained through the DataSource object is the same as the connection obtained through the DriverManager facility.

    5. DataSource's own approach

      1. Connection getconnection () attempts to establish a connection to the data source represented by this DataSource object

      2. Connection getconnection (String username,string Passward) attempts to establish a connection to the data source represented by this DataSource object

      3. Inherited method Commondatasource Wrapper,commondatasource above has explained not to repeat, say Wrapper method

          1. Boolean iswrappsefor (Class iface)



This article is from the "Grok World" blog, please be sure to keep this source http://7449328.blog.51cto.com/7439328/1909676

How to connect in db practice

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.