Listas ODBCs Cadastradas[RESOLVIDO]

1 resposta
douglasrauber

Boa tarde!

Preciso listar as conexões ODBC configuradas (exclusivamente windows) em um APP swing para fazer uma “janela de acesso”.
Usuário:
Senha:
Conexão: (Combobox listando todas conexões configuradas no Windows)
(OK) (Cancelar)

Alguém tem uma dica de como posso fazer isso?

Obrigado

Douglas

1 Resposta

douglasrauber

Fiz assim:

package teste;

/**
 * OdbcSystemDSNListUtil.java
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class OdbcSystemDSNListUtil {

    public static Set getODBCSystemDNSUser() {
        String PERSONAL_FOLDER_CMD = "HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI";
        String[] command = new String[]{"reg", "query", PERSONAL_FOLDER_CMD};
        Set dsnList = new HashSet();
        try {
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader stream = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String dsn = "";
            while ((dsn = stream.readLine()) != null) {
                if (dsn.indexOf(PERSONAL_FOLDER_CMD + "\") != -1) {
                    dsnList.add(dsn.substring(dsn.lastIndexOf("\") + 1));
                }
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
        return dsnList;
    }

    public static Set getODBCSystemDNSSistema() {
        String PERSONAL_FOLDER_CMD = "HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI";
        String[] command = new String[]{"reg", "query", PERSONAL_FOLDER_CMD};
        Set dsnList = new HashSet();
        try {
            Process process = Runtime.getRuntime().exec(command);
            BufferedReader stream = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String dsn = "";
            while ((dsn = stream.readLine()) != null) {
                if (dsn.indexOf(PERSONAL_FOLDER_CMD + "\") != -1) {
                    dsnList.add(dsn.substring(dsn.lastIndexOf("\") + 1));
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return dsnList;
    }

    public static void main(String[] args) {
        Set dsnList = getODBCSystemDNSUser();
        for (Object dsn : dsnList) {
            System.out.println("dsn name: " + dsn);
        }
        dsnList = null;
        dsnList = getODBCSystemDNSSistema();
        for (Object dsn : dsnList) {
            System.out.println("dsn name: " + dsn);
        }
    }
}

douglasrauber:
Boa tarde!

Preciso listar as conexões ODBC configuradas (exclusivamente windows) em um APP swing para fazer uma “janela de acesso”.
Usuário:
Senha:
Conexão: (Combobox listando todas conexões configuradas no Windows)
(OK) (Cancelar)

Alguém tem uma dica de como posso fazer isso?

Obrigado

Douglas

Criado 30 de maio de 2011
Ultima resposta 30 de mai. de 2011
Respostas 1
Participantes 1