Display All Available JDBC/ODBC Data Sources

Discussion in 'Java' started by Rich, Dec 10, 2003.

  1. Rich

    Rich Guest

    All,

    I'm working on a piece of code to allow the user to select from a list
    of JDBC/ODBC data sources. For example, assume I have four Access ODBC
    data sources. How do I enumerate these?

    After a lot of searching on Google, I found the following:

    /////////////////////////////////////////////////////////////////////////
    Enumeration enum = DriverManager.getDrivers();
    System.out.println(" Before - while (enum.hasMoreElements())");
    while (enum.hasMoreElements())
    {
    System.out.println("Has Driver");
    System.out.println(enum.nextElement().toString());
    }
    System.out.println(" After - while (enum.hasMoreElements())");
    /////////////////////////////////////////////////////////////////////////

    However, it does not return anything. Does the JDBC/ODBC bridge need
    to be configured? I am missing something here?

    Thanks,

    RB
     
    Rich, Dec 10, 2003
    #1
    1. Advertising

  2. Rich

    A Baba Guest

    JDBC does not have a DSN like ODBC and there is no way you can enumerate
    existing ODBC DSNs in Java. The only way to do that is to use JNI and
    get ODBC datasource either by using ODBC API or quering Windows registry.

    DriverManager.getDrivers() get you all the drivers that are currently
    loaded in memory, not DSN names.

    Regards,
    AB


    ====================================================
    You don't pay to get spam, why pay to clean it

    Visit http://www.spammarshall.com for details
    ====================================================

    Rich wrote:
    > All,
    >
    > I'm working on a piece of code to allow the user to select from a list
    > of JDBC/ODBC data sources. For example, assume I have four Access ODBC
    > data sources. How do I enumerate these?
    >
    > After a lot of searching on Google, I found the following:
    >
    > /////////////////////////////////////////////////////////////////////////
    > Enumeration enum = DriverManager.getDrivers();
    > System.out.println(" Before - while (enum.hasMoreElements())");
    > while (enum.hasMoreElements())
    > {
    > System.out.println("Has Driver");
    > System.out.println(enum.nextElement().toString());
    > }
    > System.out.println(" After - while (enum.hasMoreElements())");
    > /////////////////////////////////////////////////////////////////////////
    >
    > However, it does not return anything. Does the JDBC/ODBC bridge need
    > to be configured? I am missing something here?
    >
    > Thanks,
    >
    > RB
     
    A Baba, Dec 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jb
    Replies:
    1
    Views:
    475
  2. Keith Wansbrough

    Re: jdbc help:sun.jdbc.odbc.JdbcOdbcDriver

    Keith Wansbrough, Aug 16, 2004, in forum: Java
    Replies:
    0
    Views:
    769
    Keith Wansbrough
    Aug 16, 2004
  3. cc
    Replies:
    2
    Views:
    535
  4. Alex Molochnikov

    List available data sources in EJB

    Alex Molochnikov, Mar 9, 2005, in forum: Java
    Replies:
    1
    Views:
    451
    Alex Molochnikov
    Mar 10, 2005
  5. Betty
    Replies:
    1
    Views:
    9,892
    Juha Laiho
    May 21, 2005
Loading...

Share This Page