Solved

How to get DSN(Data Source Name)s using java

Posted on 2000-03-16
4
608 Views
Last Modified: 2008-02-01
Hi there,
    How can i get all the DSN(Data Source Name)s created in my system using java.any help..........

sample code would be appreciated.

Thanx inadvance.

Madhusr
0
Comment
Question by:madhusr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 1

Expert Comment

by:BillyAbbott
ID: 2624169
i'm fauirly sure that you can;t using normal java, but there might be a microsoft extensiojn which does it. as far as i know dsn's are only used in wondows systems, so an ms only extension shouldn't be too much of a problem.
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2624359
ODBC Data Sources are available from the Windows registry as subkeys of HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC Data Sources.

There is no builtin Java facility for accessing the Windows registry. What you need to do is call the Win32 Registry APIs using JNI. If you've never done any JNI programming before, this can be a daunting task.

There is a free collection (for commercial or non-commercial use) of Java classes and native code called JObjects that will give you access to the Windows registry to create, read, and delete keys from a Java program. It can be downloaded from http://www.jobjects.com/products/jst/.

Another, distributed under the GPL with source can be found at http://www.trustice.com/java/jnireg/index.shtml.

This is a comment, not an answer, because I haven't personally used either of these packages and cannot post code as you requested. However, If I understand your question correctly, this is what you will need to do.

Best regards,
Jim Cakalic
0
 
LVL 19

Expert Comment

by:Jim Cakalic
ID: 2624475
ODBC Data Sources are available from the Windows registry as subkeys of HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI\ODBC Data Sources.

There is no builtin Java facility for accessing the Windows registry. What you need to do is call the Win32 Registry APIs using JNI. If you've never done any JNI programming before, this can be a daunting task.

There is a free collection (for commercial or non-commercial use) of Java classes and native code called JObjects that will give you access to the Windows registry to create, read, and delete keys from a Java program. It can be downloaded from http://www.jobjects.com/products/jst/.

Another, distributed under the GPL with source can be found at http://www.trustice.com/java/jnireg/index.shtml.

This is a comment, not an answer, because I haven't personally used either of these packages and cannot post code as you requested. However, If I understand your question correctly, this is what you will need to do.

Best regards,
Jim Cakalic
0
 
LVL 19

Accepted Solution

by:
Jim Cakalic earned 100 total points
ID: 2624486
Well, shucks! I updated the page in my browser and it posted my last comment again. Sorry.

Here is some example code using the JObjects toolkit. This is a direct ripoff of one of the sample classes included in the package.

import com.jobjects.jst.*;
import java.util.*;

public class WindowsDataSources {

    public WindowsDataSources() {
        // check registry support
        if (!SystemToolkit.doesSupportRegistry()) {
            System.out.println( "No registry support." );
        }
    }

    public void list() {
        int topkey = RegistryKey.KEY_LOCAL_MACHINE;
        String subkey = "Software\\ODBC\\ODBC.INI\\ODBC Data Sources";
        try {
            // get registry manager instance
            RegistryManager regManager = SystemToolkit.getRegistryManager();
            // create key reference
            RegistryKey key = regManager.openRegistryKey(topkey, subkey);
           
            if (key.exists()) {
                // enumerate properties
                Enumeration e = key.properties();
                while (e.hasMoreElements()) {
                    String name = (String)e.nextElement();
                    System.out.println(name);
                    //String val = key.getStringProperty(name);
                    //System.out.println( "  " + name + " = " + val );
                }
            }
        } catch (RegistryException re) {
            re.printStackTrace();
        }
    }

    public static void main(String[] args) {
        WindowsDataSources dataSources = new WindowsDataSources();
        dataSources.list();
    }
}

Jim Cakalic
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question