Connection configuration for Da Meng database

Source: Internet
Author: User
Tags driver manager

Database access is a very important part of database application system. As a common database management system, the Da Meng database provides a variety of database access interfaces, including ODBC, JDBC, API, OLE DB, and embedded methods. This article mainly lists the common way to connect to the dream database in Java ...

1. Establish a basic JDBC connection

JDBC (Java Database Connectivity) is the interface specification for Java applications and databases, designed to allow database developers to provide standard database application programming interfaces (APIs) for Java programmers. JDBC defines a common SQL database API across databases and across platforms. DM JDBC 3.0 driver complies with Sun JDBC3.0 Standard, compatible DM JDBC 2.0.

The DM jdbc Driver is a JDBC driver for the DM database, a general-purpose low-level application programming interface that supports basic SQL functionality, and supports general SQL database access.

To establish a JDBC connection, you first register the database driver. You can explicitly register the driver by calling the Registerdriver method of the Java.sql.DriverManager class, or you can register the driver implicitly by loading the database driver class.

//显示注册
DriverManager.registerDriver(newdm.jdbc.driver.dmDriver());
//隐式注册
Class.forName(“dm.jdbc.driver.DmDriver”);

The class that implements the Java.sql.Driver is loaded during implicit registration, and there is a static code snippet in the class that registers the class with the driver manager DriverManager during class loading. The code snippet for this static execution is actually the above explicitly registered code.

After registering the driver, you can call the driver Manager's Getconnection method to establish the connection. Establishing a database connection requires specifying a URL that marks a different database, the username user and password password to log on to the database.

The specific process of establishing a connection through DriverManager, as in the following example:

String driver= "dm.jdbc.driver.DmDriver";
   String url= "jdbc:dm://localhost:12345/dbname";
   String username="username";
   String password="password";
   Connection con = null;
   try {
     // 加载JDBC驱动程序
     Class.forName(driver);
   } catch (java.lang.ClassNotFoundException e) {
     e.printStackTrace();
   }
   try {
     // 数据库连接
     con = DriverManager.getConnection(url, username, password);
   } catch (SQLException ex) {
     ex.printStackTrace();
}

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.