Subject Re: Database connection
Author unicolet2003
Even better, since not always you can control the env on the server
where your app will run (and if you are developing a web app you could
have more than one app on the same machine...), you can store those
properties in .properties file.
If the file is in your classpath you can use the ClassLoader to load
the resource, return a stream and use that to initialize a Properties
object.
This way you only have to edit a text file and you are not tied to
hardcoded locations where this file should be placed.

An example of such a file would be:

jdbc.driver=org.firebirdsql.jdbc.FBDriver
jdbc.url=jdbc:firebirdsql:192.168.0.115/3050:/whatever.gdb
jdbc.login=sa
jdbc.password=test

HTH,
Umberto


--- In Firebird-Java@yahoogroups.com, "Roman Rokytskyy"
<rrokytskyy@a...> wrote:
> > I would like to set in one place the database connection variables
> > like
> >
> > Class.forName ("org.firebirdsql.jdbc.FBDriver") ;
> > java.sql.Connection connection = java.sql.DriverManager.getConnection
> > ("jdbc:firebirdsql:192.168.0.115/3050:
> >
/home/firebird/data/database.fdb?lc_ctype=ISO8859_1","SYSDBA","passwd");
> >
> > so if the database or passwd change, I only have to change it at one
> > place.
> >
> >
> > Thus some one have an idea or example?
>
> In shell you just export
>
> export ISC_USER=SYSDBA
> export ISC_PASSWORD=masterkey
>
> and in Java you use:
>
> String user = System.getenv("ISC_USER");
> String password = System.getenv("ISC_PASSWORD");
>
> if (user == null || password == null)
> throw new MyException("Either user name or password is not set.");
>
> java.sql.Connection connection =
> java.sql.DriverManager.getConnection(
> "jdbc:firebirdsql:192.168.0.115/3050:/database.fdb",
> user,
> password
> );
>
>
>
> Roman