Beruflich Dokumente
Kultur Dokumente
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
// handle the error
}
}
After the driver has been registered with the DriverManager, you can obtain a Connection instance
that is connected to a particular database by calling DriverManager.getConnection():
Example 6.1 Connector/J: Obtaining a connection from the DriverManager
If you have not already done so, please review the portion of Section 6.1, Connecting to MySQL Using
the JDBC DriverManager Interface above before working with the example below.
This example shows how you can obtain a Connection instance from the DriverManager. There are a
few different signatures for the getConnection()method. Consult the API documentation that comes
with your JDK for more specific information on how to use them.
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
...
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());