Java Reference
In-Depth Information
System
.
out
.
println
(
"Message: "
+
warn
.
getMessage
());
System
.
out
.
println
(
"Vendor: "
+
warn
.
getErrorCode
());
System
.
out
.
println
(
""
);
warn
=
warn
.
getNextWarning
();
}
// Do something with the connection here...
conn
.
close
();
// All done with that DB connection
}
catch
catch
(
ClassNotFoundException e
) {
System
.
out
.
println
(
"Can't load driver "
+
e
);
}
catch
catch
(
SQLException e
) {
System
.
out
.
println
(
"Database access failed "
+
e
);
}
}
}
I've enabled two verbosity options in this example. The use of
DriverMan-
ager.setLogStream()
causes any logging to be done to the standard error, and the
Connec-
tion
object's
getWarnings()
prints any additional warnings that come up.
When I run it on a system that doesn't have ODBC installed, I get the following outputs.
They are all from the
setLogStream()
except for the last one, which is a fatal error:
Getting Connection
JDBC to ODBC Bridge: Checking security
*Driver.connect (jdbc:odbc:Companies)
JDBC to ODBC Bridge: Checking security
JDBC to ODBC Bridge 1.2001
Current Date/Time: Fri Jun 16 16:18:45 GMT-5:00 2000
Loading JdbcOdbc library
Unable to load JdbcOdbc library
Unable to load JdbcOdbc library
Unable to allocate environment
Database access failed java.sql.SQLException: driver not found:
jdbc:odbc:Companies
On a system with JDBC installed, the connection goes further and verifies that the named
database exists and can be opened.