Re: datasource without JNDI?
From: Lee Fesperman (firstsql_at_ix.netcom.com)
Date: 08/26/04
- Next message: Lee Fesperman: "Re: mySQL Database to a TextArea?"
- Previous message: Ryan: "SQL Server - Specifying Database Name/Owner Name when using prepareCall statement"
- In reply to: kaeli: "datasource without JNDI?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 26 Aug 2004 02:42:12 GMT
kaeli wrote:
>
> Is there a way to use a datasource to connect to a DB besides using JNDI?
> Right now, my connection string is hard-coded and it's a minor pain to change
> between the production and test databases. I'd prefer to have it in a config
> file somehow, but JNDI seems like way more than I need for a small
> application.
> Any hints?
Just instantiate the datasource (it must have a no-args ctor), set the connection
properties and call getConnection(). For example:
javax.sql.DataSource ds = new com.vendor.DataSource();
ds.setServerName("godzilla");
ds.setPortNumber(9999);
java.sql.Connection connection = ds.getConnection("kaeli", "tiger");
You'll need to check the vendor docs or use reflection/inspection to find out the
connection properties.
-- Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com) ============================================================== * The Ultimate DBMS is here! * FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
- Next message: Lee Fesperman: "Re: mySQL Database to a TextArea?"
- Previous message: Ryan: "SQL Server - Specifying Database Name/Owner Name when using prepareCall statement"
- In reply to: kaeli: "datasource without JNDI?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|