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. Advertisements

  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. Advertisements

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:
    554
  2. cc
    Replies:
    2
    Views:
    614
  3. Alex Molochnikov

    List available data sources in EJB

    Alex Molochnikov, Mar 9, 2005, in forum: Java
    Replies:
    1
    Views:
    517
    Alex Molochnikov
    Mar 10, 2005
  4. Betty
    Replies:
    1
    Views:
    10,261
    Juha Laiho
    May 21, 2005
  5. Jesus M. Salvo Jr.
    Replies:
    2
    Views:
    4,509
    robert
    Feb 11, 2006
  6. Bruce
    Replies:
    4
    Views:
    963
    Bjorn Abelli
    Mar 25, 2006
  7. Erwin S. Andreasen

    Making dynamic data available via ODBC with Python

    Erwin S. Andreasen, Feb 7, 2005, in forum: Python
    Replies:
    1
    Views:
    338
    Diez B. Roggisch
    Feb 7, 2005
  8. Replies:
    6
    Views:
    6,698
Loading...