I'm trying do develop a Java tool that collect some information from Microsoft Windows Management Instrumentation (WMI) using the WMI ODBC driver. But I can't get a connection. Does anyone know how to use Java to connect WMI throgh WMI ODBC driver?
First I installed and configured the driver. (I'm using win2000) I wrote a simple test to connect but I can't get a connection.
This is my code: import java.sql.*; // needed for JDBC access
public class Teste { public static void main(String args[]) { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); System.out.println("ODBC Driver Found"); String url = "jdbc:odbc:WMI"; Connection con = DriverManager.getConnection(url, "john", "secret"); } catch (ClassNotFoundException ex) { System.out.println("ODBC Driver not found"); System.err.println("Exception: " + ex.getMessage()); } catch (SQLException ex) { System.out.println("Connection couldn't be established"); System.err.println("Exception: " + ex.getMessage()); } catch (Exception ex) { System.err.println("Exception: " + ex.getMessage()); } } }
===
And I got this when running the code above:
ODBC Driver Found Connection couldn't be established Exception: [Microsoft][WBEM ODBC Driver]Unable to connect