• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java action Class

 
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a website developed on struts frame work..
In my action class I have used Connection conurl=("jdbc:mysql://localhost:3306/DB_Name?"+"user=root&password=pwd");
Now my dout is when I host my website should i change the ://localhost:3306/DB_Name?"+"user=root&password=pwd" according the services providers.. If so should I change it for every action class.

Thank you in advance

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should refactor the code so that the DB connection parameters are not hardcoded, but instead read from an external config file. That way, you only need to change the file, but not anything in the source code.
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:You should refactor the code so that the DB connection parameters are not hardcoded, but instead read from an external config file. That way, you only need to change the file, but not anything in the source code.




Sorry I didnt get you.. I am new to this.. What is external config file. Please help..

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should define your database connection parameters in struts-config.xml configuration file in <data-sources> tag. once you do this you can directly access your database connection in action using getDataSource(request) method. Advantage of this approch is, whenever you change your database no need to change DB parameters in all the action classess where you are accessing the DB but you have to make DB parameter changes only in configuration file.

Please go through the link for sample code
http://struts.apache.org/1.2.x/faqs/database.html
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mahi,
If you aren't using Struts, Ulf is just referring to a ".properties" file. It's a file with name=value pairs. That way you can change the configuration without having to recompile the code.
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shivendra tripathi wrote:You should define your database connection parameters in struts-config.xml configuration file in <data-sources> tag. once you do this you can directly access your database connection in action using getDataSource(request) method. Advantage of this approch is, whenever you change your database no need to change DB parameters in all the action classess where you are accessing the DB but you have to make DB parameter changes only in configuration file.

Please go through the link for sample code
http://struts.apache.org/1.2.x/faqs/database.html




Thank you for the reply. The link really helped me.

 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Mahi,
If you aren't using Struts, Ulf is just referring to a ".properties" file. It's a file with name=value pairs. That way you can change the configuration without having to recompile the code.




Thank you ..

 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no problem Mahi
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic