Where to go net internship Summary: How to configure Database Connectivity (Javaweb)

Source: Internet
Author: User

Originally to do the purpose of data mining in which network, the structure has become a system development ...

But still more serious to do for three months, the teacher is very agree with my work attitude and results ...

The internship is coming to an end, summarizing a few things that have not been noticed before to become habits and problems, to share to everyone.


At the same time to play an advertisement: to which network Internal audit department recruit Javaweb Development intern, Time is very free, a week, Saturday Sunday even can, the time of the small partners to give me a message ah, earn a pocket money, but also a long experience .... (GPA, want to work a senior dog is the most suitable ... )



In the company, the development system often uses the development environment, the real environment only after the system development is good, only then can go on the line to use, then how the database connection configures?

The answer is to use the. properties file configuration. Directly on the code:

Dbconfig.properties:

#development Environmentserver_oa = ***port_oa = ***user_oa = ***pass_oa = ***dbname_oa = <span style= "Font-family:ari Al, Helvetica, Sans-serif; >oadb</span> #real Environment#server_oa = <span style= "font-family:arial, Helvetica, Sans-serif;" >***</span> #port_oa = <span style= "font-family:arial, Helvetica, Sans-serif;" >***</span> #user_oa = <span style= "font-family:arial, Helvetica, Sans-serif;" >***</span> #pass_oa = <span style= "font-family:arial, Helvetica, Sans-serif;" >***</span> #dbname_oa = oadb



In the DB Class:

public class DBConnection {public static string server_oa;public static string Port_oa;public static string User_oa;public static string Pass_oa;public static string Dbname_oa;public static string Url_oa;static{try {Properties Properties = new Properties (); InputStream instream = Thread.CurrentThread (). Getcontextclassloader (). getResourceAsStream (" Dbconfig.properties ");p roperties.load (instream), Server_oa = Properties.getproperty (" Server_oa ");p Ort_oa = Properties.getproperty ("Port_oa"), User_oa = Properties.getproperty ("User_oa");p Ass_oa = Properties.getproperty (" Pass_oa ");d Bname_oa = Properties.getproperty (" Dbname_oa "); Url_oa =" jdbc:mysql://"+ Server_oa +": "+ Port_oa +"/"+ DBN ame_oa+ "? user=" + User_oa + "&password=" + Pass_oa;} catch (IOException e) {e.printstacktrace ();}}}


In this way, as long as you publish your own system, the environment changed, configure the Dbconfig.properties file can ....


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Where to go net internship Summary: How to configure Database Connectivity (Javaweb)

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.