Re: datasource without JNDI?

From: Lee Fesperman (firstsql_at_ix.netcom.com)
Date: 08/26/04


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)


Relevant Pages

  • Re: Binding to JNDI datasource - please help
    ... I'm relatively new to JNDI concepts and need some help. ... > connection datasource as a url variable. ... > How do I use this JNDI name to create a connection? ... > literature I have read says to bind the resource manager connection ...
    (comp.lang.java.programmer)
  • Re: MS Access setup with javax.sql and DataSource objects
    ... > system setup with JNDI... ... I'm not sure what you mean by "DataSource" in this case, ... public AccessDataSource throws SQLException ... public Connection getConnection() throws SQLException ...
    (comp.lang.java.databases)
  • Binding to JNDI datasource - please help
    ... Binding to JNDI datasource - please help ... I'm relatively new to JNDI concepts and need some help. ... How do I use this JNDI name to create a connection? ... factory reference (res-ref-name) to the in the server ...
    (comp.lang.java.programmer)
  • Re: DataSource problem
    ... I think you want to use a connection pool??? ... All you have to do is make your datasource available via jndi. ... >>cannot connect to the database without finding or buying a JDBC driver. ...
    (comp.lang.java.databases)
  • Re: Reading mm datasource
    ... When in Word on my machine, I click on open datasource, pick Connect ... > do not seem to have a specific driver name for the connection string. ... But before you go much further, I hadn't realised you were taking that particular approach to making the connection, and AFAIK the consequence is likely to be that you will be opening your data source, using the "OLE DB Provider for ODBC data sources" which is an approach I know little about but will ...
    (microsoft.public.word.mailmerge.fields)