title: Making an ODBC connection through System DSN set up under Windows ODBC Data Source Administrator?
body: <p>I'm trying to make an ODBC connection in Java through Windows ODBC Manager.  I have managed to read the registry to get a listing of System DSNs and once a selection is made by the user I read the "HostMachine" parameter in the registry associated with the selected SystemDSN and from there I want to make that ODBC connection.  I have tried the DriverManager getConnection method but it doesn't seem to work!  Any ideas PLZ??!</p>
  
  <p>Please note that I want to access the servers through their associated IP addresses and less likely urls, hence (HostMachine)!</p>
  
  <p>Also each of these System DSNs are associated with a driver that would need to be used to connect its related data source!</p>
  
  <pre><code>private static Connection getConnection(String address, String username, String password) throws Exception {
      String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
      String url = "jdbc:odbc:" + address;
      Class.forName(driver);
      return DriverManager.getConnection(url, username, password);
  }
  </code></pre>
  
  <p>I'm getting the following exception!</p>
  
  <pre><code>java.sql.SQLException: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
  </code></pre>
  
  <p>Thanks Dan, I did as you said but now I'm getting this exception, what do you think??!</p>
  
  <pre><code>java.sql.SQLException: General error
      at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
  </code></pre>
  
  <p>Here's the complete stack trace!  Any ideas please??! </p>
  
  <pre><code>java.sql.SQLException: General error
  at sun.jdbc.odbc.JdbcOdbc.createSQLException(Unknown Source)
  at sun.jdbc.odbc.JdbcOdbc.standardError(Unknown Source)
  at sun.jdbc.odbc.JdbcOdbc.SQLDriverConnect(Unknown Source)
  at sun.jdbc.odbc.JdbcOdbcConnection.initialize(Unknown Source)
  at sun.jdbc.odbc.JdbcOdbcDriver.connect(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  at java.sql.DriverManager.getConnection(Unknown Source)
  </code></pre>