Logo Search packages:      
Sourcecode: mysql-connector-java version File versions

com::mysql::jdbc::Connection::Connection ( String  hostToConnectTo,
int  portToConnectTo,
Properties  info,
String  databaseToConnectTo,
String  url,
NonRegisteringDriver  d 
) throws SQLException [inline, package]

Creates a connection to a MySQL Server.

hostToConnectTo the hostname of the database server
portToConnectTo the port number the server is listening on
info a Properties[] list holding the user and password
databaseToConnectTo the database to connect to
url the URL of the connection
d the Driver instantation of the connection
SQLException if a database access error occurs

Definition at line 359 of file Connection.java.

References cleanup(), connectionCreationTimeMillis, createNewIO(), database, dbmd, com::mysql::jdbc::ConnectionProperties::getLogger(), com::mysql::jdbc::ConnectionProperties::getParanoid(), host, hostList, hostListSize, initializeDriverProperties(), log, LOGGER_INSTANCE_NAME, myURL, openStatements, password, pointOfOrigin, port, props, serverVariables, and user.

Referenced by com::mysql::jdbc::NonRegisteringDriver::connect().

        this.connectionCreationTimeMillis = System.currentTimeMillis();
        this.pointOfOrigin = new Throwable();

        // Normally, this code would be in initializeDriverProperties,
        // but we need to do this as early as possible, so we can start 
        // logging to the 'correct' place as early as possible...this.log 
        // points to 'NullLogger' for every connection at startup to avoid 
        // NPEs and the overhead of checking for NULL at every logging call.
        // We will reset this to the configured logger during properties
        // initialization.
        this.log = LogFactory.getLogger(getLogger(), LOGGER_INSTANCE_NAME);

        // We store this per-connection, due to static synchronization
        // issues in Java's built-in TimeZone class...
        this.defaultTimeZone = TimeZone.getDefault();
        if ("GMT".equalsIgnoreCase(this.defaultTimeZone.getID())) {
            this.isClientTzUTC = true;
        } else {
            this.isClientTzUTC = false;

        this.openStatements = new HashMap();
        this.serverVariables = new HashMap();
        this.hostList = new ArrayList();

        if (hostToConnectTo == null) {
            this.host = "localhost";
        } else if (hostToConnectTo.indexOf(",") != -1) {
            // multiple hosts separated by commas (failover)
            StringTokenizer hostTokenizer = new StringTokenizer(hostToConnectTo,
                    ",", false);

            while (hostTokenizer.hasMoreTokens()) {
        } else {
            this.host = hostToConnectTo;

        this.hostListSize = this.hostList.size();
        this.port = portToConnectTo;

        if (databaseToConnectTo == null) {
            databaseToConnectTo = "";

        this.database = databaseToConnectTo;
        this.myURL = url;
        this.user = info.getProperty(NonRegisteringDriver.USER_PROPERTY_KEY);
        this.password = info.getProperty(NonRegisteringDriver.PASSWORD_PROPERTY_KEY);

        if ((this.user == null) || this.user.equals("")) {
            this.user = "";

        if (this.password == null) {
            this.password = "";

        this.props = info;

        try {
            this.dbmd = new DatabaseMetaData(this, this.database);
        } catch (SQLException ex) {
            cleanup(new Throwable(), ex);

            // don't clobber SQL exceptions
            throw ex;
        } catch (Exception ex) {
            cleanup(new Throwable(), ex);

            StringBuffer mesg = new StringBuffer();

            if (getParanoid()) {
                mesg.append("Cannot connect to MySQL server on ");
                mesg.append("Make sure that there is a MySQL server ");
                mesg.append("running on the machine/port you are trying ");
                    "to connect to and that the machine this software is "
                    + "running on ");
                mesg.append("is able to connect to this host/port "
                    + "(i.e. not firewalled). ");
                    "Also make sure that the server has not been started "
                    + "with the --skip-networking ");
            } else {
                mesg.append("Unable to connect to database.");

            mesg.append("Underlying exception: \n\n");

            if (!getParanoid()) {

            throw new SQLException(mesg.toString(),

Generated by  Doxygen 1.6.0   Back to index