diff -uNr postgresql-7.4.1-orig/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java postgresql-7.4.1/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java
--- postgresql-7.4.1-orig/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java	Wed May 28 22:21:32 2003
+++ postgresql-7.4.1/src/interfaces/jdbc/org/postgresql/core/StartupPacket.java	Fri Feb 13 14:47:02 2004
@@ -1,6 +1,8 @@
 package org.postgresql.core;
 
 import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Enumeration;
 
 /**
  * Sent to the backend to initialize a newly created connection.
@@ -21,12 +23,43 @@
 	private String user;
 	private String database;
 
-	public StartupPacket(int protocolMajor, int protocolMinor, String user, String database)
+	/*
+	 * Extra params can be sent to the server starting with the V2 wire
+	 * protocol.  This Hashtable holds these extra parameters.
+	 *
+	 * Changed by Chris Smith <cdsmith@twu.net>
+	 */
+	private Hashtable params;
+
+	public StartupPacket(int protocolMajor, int protocolMinor,
+	    String user, String database)
+	{
+		this.protocolMajor = protocolMajor;
+		this.protocolMinor = protocolMinor;
+		this.user = user;
+		this.database = database;
+
+		this.params = new Hashtable();
+	}
+
+	public StartupPacket(int protocolMajor, int protocolMinor,
+		String user, String database, Hashtable params)
 	{
+		/*
+		 * The extra arguments from this constructor are only
+		 * available in v3 of the wire protocol.
+		 */
+		if ((protocolMajor < 3) && !params.isEmpty())
+		{
+			throw new IllegalArgumentException();
+		}
+
 		this.protocolMajor = protocolMajor;
 		this.protocolMinor = protocolMinor;
 		this.user = user;
 		this.database = database;
+
+		this.params = params;
 	}
 
 	public void writeTo(PGStream stream) throws IOException
@@ -40,7 +73,27 @@
 
 	public void v3WriteTo(PGStream stream) throws IOException
 	{
-		stream.SendInteger(4 + 4 + "user".length() + 1 + user.length() + 1 + "database".length() +1 + database.length() + 1 + 1, 4);
+		/*
+		 * Precalculate message length.
+		 */
+		int length = 4 + 4;
+		length += "user".length() + 1 + user.length() + 1;
+		length += "database".length() + 1 + database.length() + 1;
+
+		Enumeration en = params.keys();
+		while (en.hasMoreElements())
+		{
+			String name = (String) en.nextElement();
+			String value = (String) params.get(name);
+			length += name.length() + 1 + value.length() + 1;
+		}
+
+		length += 1;
+
+		/*
+		 * Send the startup message.
+		 */
+		stream.SendInteger(length, 4);
 		stream.SendInteger(protocolMajor, 2);
 		stream.SendInteger(protocolMinor, 2);
 		stream.Send("user".getBytes());
@@ -51,11 +104,27 @@
 		stream.SendChar(0);
 		stream.Send(database.getBytes());
 		stream.SendChar(0);
+
+		en = params.keys();
+		while (en.hasMoreElements())
+		{
+			String name = (String) en.nextElement();
+			String value = (String) params.get(name);
+			stream.Send(name.getBytes());
+			stream.SendChar(0);
+			stream.Send(value.getBytes());
+			stream.SendChar(0);
+		}
+
 		stream.SendChar(0);
 	}
 
 	public void v2WriteTo(PGStream stream) throws IOException
 	{
+		/*
+		 * For wire protocol v2, the extra params are guaranteed to be
+		 * empty, and are therefore ignored.
+		 */
 		stream.SendInteger(4 + 4 + SM_DATABASE + SM_USER + SM_OPTIONS + SM_UNUSED + SM_TTY, 4);
 		stream.SendInteger(protocolMajor, 2);
 		stream.SendInteger(protocolMinor, 2);
diff -uNr postgresql-7.4.1-orig/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java postgresql-7.4.1/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java
--- postgresql-7.4.1-orig/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java	Wed Dec 17 21:29:12 2003
+++ postgresql-7.4.1/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1Connection.java	Fri Feb 13 14:45:42 2004
@@ -218,6 +218,13 @@
 
 	private void openConnectionV3(String p_host, int p_port, Properties p_info, String p_database, String p_url, Driver p_d, String p_password) throws SQLException
 	  {
+	    // NOTE: To simplify this code, it is assumed that if we are
+	    // using the V3 protocol, then the database is at least 7.4.  That
+	    // eliminates the need to check database versions and maintain
+	    // backward-compatible code here.
+	    //
+	    // Change by Chris Smith <cdsmith@twu.net>
+
 		PGProtocolVersionMajor = 3;
 		if (Driver.logDebug)
 			Driver.debug("Using Protocol Version3");
@@ -275,14 +282,21 @@
 		// Now we need to construct and send a startup packet
 		try
 		{
+			Hashtable params = new Hashtable();
+			params.put("client_encoding", "UNICODE");
+			params.put("DateStyle", "ISO");
 			new StartupPacket(PGProtocolVersionMajor,
 							  PGProtocolVersionMinor,
-							  PG_USER,
-							  p_database).writeTo(pgStream);
+							  PG_USER, p_database, params)
+				.writeTo(pgStream);
 
 			// now flush the startup packets to the backend
 			pgStream.flush();
 
+			// The startup request has been sent with the UNICODE encoding.
+			// From here out, everything should be in Unicode.
+			encoding = Encoding.getEncoding("UNICODE", null);
+
 			// Now get the response from the backend, either an error message
 			// or an authentication request
 			int areq = -1; // must have a value here
@@ -450,9 +464,17 @@
 			    case 'S':
 					//TODO: handle parameter status messages
 					int l_len = pgStream.ReceiveIntegerR(4);
-					String l_pStatus = encoding.decode(pgStream.Receive(l_len-4));
+					String name = pgStream.ReceiveString(encoding);
+					String value = pgStream.ReceiveString(encoding);
+
 					if (Driver.logDebug)
-						Driver.debug("ParameterStatus="+ l_pStatus);
+						Driver.debug("ParameterStatus: " + name + "=" + value);
+
+					if (name.equals("server_version"))
+					{
+						dbVersionNumber = value;
+					}
+
 					break;
 				default:
 					if (Driver.logDebug)
@@ -461,60 +483,12 @@
 			}
 		}
 		while (beresp != 'Z');
+
 		// read ReadyForQuery
 		if (pgStream.ReceiveIntegerR(4) != 5) throw new PSQLException("postgresql.con.setup", PSQLState.CONNECTION_UNABLE_TO_CONNECT); 
+
 		//TODO: handle transaction status
 		char l_tStatus = (char)pgStream.ReceiveChar();
-
-		// "pg_encoding_to_char(1)" will return 'EUC_JP' for a backend compiled with multibyte,
-		// otherwise it's hardcoded to 'SQL_ASCII'.
-		// If the backend doesn't know about multibyte we can't assume anything about the encoding
-		// used, so we denote this with 'UNKNOWN'.
-		//Note: begining with 7.2 we should be using pg_client_encoding() which
-		//is new in 7.2.  However it isn't easy to conditionally call this new
-		//function, since we don't yet have the information as to what server
-		//version we are talking to.  Thus we will continue to call
-		//getdatabaseencoding() until we drop support for 7.1 and older versions
-		//or until someone comes up with a conditional way to run one or
-		//the other function depending on server version that doesn't require
-		//two round trips to the server per connection
-
-		final String encodingQuery =
-			"case when pg_encoding_to_char(1) = 'SQL_ASCII' then 'UNKNOWN' else getdatabaseencoding() end";
-
-		// Set datestyle and fetch db encoding in a single call, to avoid making
-		// more than one round trip to the backend during connection startup.
-
-
-		BaseResultSet resultSet
-			= execSQL("set datestyle to 'ISO'; select version(), " + encodingQuery + ";");
-		
-		if (! resultSet.next())
-		{
-			throw new PSQLException("postgresql.con.failed.bad.encoding", PSQLState.CONNECTION_UNABLE_TO_CONNECT);
-		}
-		String version = resultSet.getString(1);
-		dbVersionNumber = extractVersionNumber(version);
-
-		String dbEncoding = resultSet.getString(2);
-		encoding = Encoding.getEncoding(dbEncoding, p_info.getProperty("charSet"));
-		//In 7.3 we are forced to do a second roundtrip to handle the case 
-		//where a database may not be running in autocommit mode
-		//jdbc by default assumes autocommit is on until setAutoCommit(false)
-		//is called.  Therefore we need to ensure a new connection is 
-		//initialized to autocommit on.
-		//We also set the client encoding so that the driver only needs 
-		//to deal with utf8.  We can only do this in 7.3 because multibyte 
-		//support is now always included
-		if (haveMinimumServerVersion("7.3")) 
-		{
-			BaseResultSet acRset =
-			//TODO: if protocol V3 we can set the client encoding in startup
-			execSQL("set client_encoding = 'UNICODE'");
-			//set encoding to be unicode
-			encoding = Encoding.getEncoding("UNICODE", null);
-
-		}
 
 		// Initialise object handling
 		initObjectTypes();
