Where to go net internship Summary: How to configure a database connection (Javaweb)

Source: Internet
Author: User

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

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

。。

The internship will be over soon. Summarize some of the things that have not been noticed before and become habits and problems and share them with you.


At the same time to make an advertisement: to which network Internal audit department recruit Javaweb Development intern. Time is very free, one day a week, Saturday Sunday and even can, the time of the small friends to give me a message ah, earn an allowance, but also a long experience.

。。。 (GPA, want to work a senior dog is the most suitable only ...



In companies, development systems tend to use the development environment. The real environment is only after the system has been developed, talent enough to use online. So how does the database connection be configured?

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 ();}}}


Such You just have to publish your system normally, and the environment changes. Configure the Dbconfig.properties file to do so.

。。。


Where to go net internship Summary: How to configure a database connection (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.