• 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 to read System environment variables!!!

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
I have a JAR application, that automatically runs by a system scheduler created by me. Now, this JAR application creates a connection to a Oracle DB everytime it runs. or creating the connection,I have hardcoded the JDBC-URL string, schema-name, and password inside the main class. Instead of hardcoding, can't I just set some System environment variables, and read it from Java? If it's possible, let me know how!!!

Give me example for UNIX, as well as Windows system.
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally I add a property file to my build and load it relative to the path used by the classloader for Main i.e. you can load it from within the jar when you deploy or from a directory when in dev (same code loads either).

You can do system properties instead but this seems neater, i.e. its all contained in the jar certainly a step up from had coding withing the class, if you don't want to do that you could just add them as command line arguments for instance.

Some stuff on it here, its done a lot so should be all over the web ..

http://forum.java.sun.com/thread.jspa?threadID=254048&messageID=959478
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Java in General (Intermediate).
 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Chris,
thanks for that link...actually I have already thought about that option, but I thought let's check out the other option,if any.But it's alright.Thanks for the reply.
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use System Properties. Try google search.
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Subhadip Chatterjee:
Hi Folks,
...
Give me example for UNIX, as well as Windows system.



I pass them via the command line, using the -D option.
If my database info is defined in the operating system property db, I use:

On Unix:


On Windows:


In java, the property can be retrieved by this code:



Java also has the function
It was deprecated in java 1.4, but isn't anymore since java 1.5.


Regards, jan
[ January 29, 2007: Message edited by: Jan Cumps ]
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic