ConnectionJDBC2(String url, Properties info) throws SQLException { this.statements = new ArrayList(); this.url = url;    unpackProperties(info); this.messages = new SQLDiagnostic(serverType);     if (instanceName.length() > 0 && !namedPipe) { final MSSqlServerInfo msInfo = new MSSqlServerInfo(serverName);  portNumber = msInfo.getPortForInstance(instanceName);  if (portNumber == -1) { throw new SQLException( Messages.get("error.msinfo.badinst", serverName, instanceName), "08003"); } }    SharedSocket.setMemoryBudget(100000); SharedSocket.setMinMemPkts(8);  try { if (namedPipe == true) {  if(System.getProperty("os.name").toLowerCase().startsWith("windows")) {  socket = new SharedLocalNamedPipe(serverName, tdsVersion, serverType, instanceName); } else {  socket = SharedNamedPipe.instance(serverName, tdsVersion, serverType, packetSize, instanceName, domainName, user, password); } } else {  socket = new SharedSocket(serverName, portNumber, tdsVersion, serverType, tcpNoDelay); }  if ( charsetSpecified ) { loadCharset(serverCharset); } else {   loadCharset("iso_1"); }     baseTds = new TdsCore(this, messages); Object timer = null;  if (loginTimeout > 0) {  timer = TimerThread.getInstance().setTimer(loginTimeout * 1000, new TimerThread.TimerListener() { public void timerExpired() { socket.forceClose(); } }); }     if (tdsVersion >= Driver.TDS80 && !namedPipe) { baseTds.negotiateSSL(instanceName, ssl); }     baseTds.login(serverName, databaseName, user, password, domainName, serverCharset, appName, progName, language, macAddress, packetSize);  if (timer != null) {  TimerThread.getInstance().cancelTimer(timer); }     tdsVersion = baseTds.getTdsVersion();  if (tdsVersion < Driver.TDS70 && databaseName.length() > 0) {  setCatalog(databaseName); } } catch (UnknownHostException e) { throw Support.linkException( new SQLException(Messages.get("error.connection.badhost", e.getMessage()), "08S03"), e); } catch (IOException e) { throw Support.linkException( new SQLException(Messages.get("error.connection.ioerror", e.getMessage()), "08S01"), e); } catch (SQLException e) { if (loginTimeout > 0 && e.getMessage().indexOf("socket closed") >= 0) { throw new SQLException( Messages.get("error.connection.timeout"), "HYT01"); }  throw e; }     if ((serverCharset == null || serverCharset.length() == 0) && collation == null) { loadCharset(determineServerCharset()); }     if (serverType == Driver.SYBASE) { baseTds.submitSQL(SYBASE_INITIAL_SQL); } else {   Statement stmt = this.createStatement(); ResultSet rs = stmt.executeQuery(SQL_SERVER_INITIAL_SQL);  if (rs.next()) { maxPrecision = rs.getByte(1); }  rs.close(); stmt.close(); }
private ConnectionJDBC2() {
    ConnectionJDBC2(String url, Properties info)            throws SQLException {        this.statements = new ArrayList();        this.url = url;        //        // Extract properties into instance variables        //        unpackProperties(info);        this.messages = new SQLDiagnostic(serverType);        //        // Get the instance port, if it is specified.        // Named pipes use instance names differently.        //        if (instanceName.length() > 0 && !namedPipe) {            final MSSqlServerInfo msInfo = new MSSqlServerInfo(serverName);            portNumber = msInfo.getPortForInstance(instanceName);            if (portNumber == -1) {                throw new SQLException(                                      Messages.get("error.msinfo.badinst", serverName, instanceName),                                      "08003");            }        }        //        // TODO These parameters should be set from the connection properties        //        SharedSocket.setMemoryBudget(100000);        SharedSocket.setMinMemPkts(8);        try {            if (namedPipe == true) {                // TODO Use namedPipe parameter to select implementation type                if(System.getProperty("os.name").toLowerCase().startsWith("windows")) {                    // If the OS is Windows, use a local named pipe                    socket = new SharedLocalNamedPipe(serverName, tdsVersion, serverType,                            instanceName);                } else {                    // Otherwise use a named pipe over TCP/IP                    socket = SharedNamedPipe.instance(serverName, tdsVersion, serverType,                            packetSize, instanceName, domainName, user, password);                }            } else {                // Use plain TCP/IP socket                socket = new SharedSocket(serverName, portNumber, tdsVersion,                        serverType, tcpNoDelay);            }            if ( charsetSpecified ) {                loadCharset(serverCharset);            } else {                // Need a default charset to process login packets for TDS 4.2/5.0                // Will discover the actual serverCharset later                loadCharset("iso_1");            }            //            // Create TDS protocol object            //            baseTds = new TdsCore(this, messages);            Object timer = null;            if (loginTimeout > 0) {                // Start a login timer                timer = TimerThread.getInstance().setTimer(loginTimeout * 1000,                        new TimerThread.TimerListener() {                            public void timerExpired() {                                socket.forceClose();                            }                        });            }            //            // Negotiate SSL connection if required            //            if (tdsVersion >= Driver.TDS80 && !namedPipe) {                baseTds.negotiateSSL(instanceName, ssl);            }            //            // Now try and login            //            baseTds.login(serverName,                          databaseName,                          user,                          password,                          domainName,                          serverCharset,                          appName,                          progName,                          language,                          macAddress,                          packetSize);            if (timer != null) {                // Cancel loginTimer                TimerThread.getInstance().cancelTimer(timer);            }            // Update the tdsVersion with the value in baseTds. baseTds sets            // the TDS version for the socket and there are no other objects            // with cached TDS versions at this point.            tdsVersion = baseTds.getTdsVersion();            if (tdsVersion < Driver.TDS70 && databaseName.length() > 0) {                // Need to select the default database                setCatalog(databaseName);            }        } catch (UnknownHostException e) {            throw Support.linkException(                    new SQLException(Messages.get("error.connection.badhost",                            e.getMessage()), "08S03"), e);        } catch (IOException e) {            throw Support.linkException(                    new SQLException(Messages.get("error.connection.ioerror",                            e.getMessage()), "08S01"), e);        } catch (SQLException e) {            if (loginTimeout > 0 && e.getMessage().indexOf("socket closed") >= 0) {                throw new SQLException(                        Messages.get("error.connection.timeout"), "HYT01");            }            throw e;        }        // If charset is still unknown and the collation is not set either,        // determine the charset by querying (we're using Sybase or SQL Server        // 6.5)        if ((serverCharset == null || serverCharset.length() == 0)                && collation == null) {            loadCharset(determineServerCharset());        }        // Initial database settings.        // Sets: auto commit mode  = true        //       transaction isolation = read committed.        if (serverType == Driver.SYBASE) {            baseTds.submitSQL(SYBASE_INITIAL_SQL);        } else {            // Also discover the maximum decimal precision (28 for MS SQL pre            // 2000, configurable to 28/38 for 2000 and later)            Statement stmt = this.createStatement();            ResultSet rs = stmt.executeQuery(SQL_SERVER_INITIAL_SQL);            if (rs.next()) {                maxPrecision = rs.getByte(1);            }            rs.close();            stmt.close();        }    }