This section describes what will happen if you specified an incorrect DSN in the connection URL when using JDBC-ODBC Bridge.
It is very common that the DSN you entered in the connection URL is not defined or defined incorrectly.
In this case, the JDBC-ODBC Bridge driver will raise an exception on the DriverManager.getConnection() method.
Here is a sample showing what kind of exception you will get if the DSN is wrong:
/**
* OdbcConnectionWrongDsn.java
* Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
*/
import java.sql.*;
public class OdbcConnectionWrongDsn {
public static void main(String [] args) {
Connection con = null;
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
// Connect with a wrong DSN
con = DriverManager.getConnection("jdbc:odbc:HY_WRONG");
System.out.println("Connection ok.");
con.close();
} catch (Exception e) {
System.err.println("Exception: "+e.getMessage());
}
}
}
If you run this program, the Microsoft ODBC Driver Manager will return
an error through the JDBC-ODBC Bridge driver:
C:\>javac OdbcConnectionWrongDsn.java
C:\>java OdbcConnectionWrongDsn
Exception: [Microsoft][ODBC Driver Manager]
Data source name not found and no default driver specified