Connection conn = drivermanager.getconnection ("Jdbc:odbc:bbs");

Source: Internet
Author: User

Connection conn = drivermanager.getconnection ("Jdbc:odbc:bbs");

This is the phrase that JDBC connects to the database, connection is an interface, DriverManager is a class, and the Getconnection () method is a static method

The reason they can connect with the = number

Because the getconnection () method returns an  instance of a class that implements the connection interface

In fact, connection is a class or interface, and under normal circumstances a variable is declared with a class,

And the interface is a specialized class, which is equivalent to the virtual base class in C + +, as long as the class implements this interface is equivalent to inherit the interface

And like a parent class variable = An instance of a subclass is common in Java, and since that's OK

So like an interface variable = An instance of a subclass can also be a row

The Getconnection () method is a static method

Class . Method () This form of method-----class method, i.e., this method can be used even if the class is not instantiated,

There are also objects. Static methods ()

And the general method can not

A factory model is a class that is called a class factory to produce instances of classes (more interfaces)

And this factory class usually has only one copy.

Connection conn = drivermanager.getconnection("");

There is no instantiation of the factory class here, only one copy

Returns an instance of a class that implements the connection interface with a static method class

Purpose---to make use of connection instances, there is no need to care about how classes of connection interfaces change

Connection conn = drivermanager.getconnection ("Jdbc:odbc:bbs");

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.