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)
packageteste;/** * OdbcSystemDSNListUtil.java */importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStreamReader;importjava.util.HashSet;importjava.util.Set;publicclassOdbcSystemDSNListUtil{publicstaticSetgetODBCSystemDNSUser(){StringPERSONAL_FOLDER_CMD="HKEY_CURRENT_USER\SOFTWARE\ODBC\ODBC.INI";String[]command=newString[]{"reg","query",PERSONAL_FOLDER_CMD};SetdsnList=newHashSet();try{Processprocess=Runtime.getRuntime().exec(command);BufferedReaderstream=newBufferedReader(newInputStreamReader(process.getInputStream()));Stringdsn="";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("dsnname:" + dsn); } dsnList = null; dsnList = getODBCSystemDNSSistema(); for (Object dsn : dsnList) { System.out.println("dsnname:" + 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)