Read the database configuration method from the configuration file in eclipse

Source: Internet
Author: User

If the configuration file is Dblink.properties, under the Conf folder in the root directory of the project,

The contents of the configuration file are as follows:

JDBCURL=JDBC:ORCALE:THIN:@172.16.5.22:1521:XXDB (database name) user=xxxx (user name) password=xxxx (password)

The configuration file is then read in your database connection class and can be read before loading the driver.

As follows:

Static {    inputstream in = dblinkdao.class.getclassloader (). getResourceAsStream ("/conf/dblink.properties");  (in this line of code, Dblinkdao is to control the scope of the search configuration file, and if the following path is an absolute path, the class can be any Java class ,. Class.getclassloader () is to get a class loader)     Properties properties = new  Properties ();     try{        properties.load (in);    (Loading parts)                   } catch  (IOEXCEPTION E1)  {         E1.printstacktrace ();      }                   conn_str = properties.getproperty (" Jdbcurl ");     db_user = properties.getproperty (" USER ");     Db_pwd = properties.getpropErty ("password");      (Load driver code)    }

After that, the normal database connection operation

Read the database configuration method from the configuration file in eclipse

Related Article

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.