=== modified file 'src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java'
--- src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java	2014-03-25 16:17:05 +0000
+++ src/main/java/org/mariadb/jdbc/internal/mysql/MySQLProtocol.java	2014-04-17 04:21:15 +0000
@@ -52,6 +52,7 @@
 
 import org.mariadb.jdbc.HostAddress;
 import org.mariadb.jdbc.JDBCUrl;
+import org.mariadb.jdbc.MySQLConnection;
 import org.mariadb.jdbc.internal.SQLExceptionMapper;
 import org.mariadb.jdbc.internal.common.*;
 import org.mariadb.jdbc.internal.common.packet.*;
@@ -427,6 +428,11 @@
            if(info.getProperty("interactiveClient") != null) {
               capabilities |= MySQLServerCapabilities.CLIENT_INTERACTIVE;
            }
+           // If a database is given, but createDB is not defined or is false,
+           // then just try to connect to the given database
+           if (database != null && !createDB())
+               capabilities |= MySQLServerCapabilities.CONNECT_WITH_DB;
+           
            if(info.getProperty("useSSL") != null &&
                    (greetingPacket.getServerCapabilities() & MySQLServerCapabilities.SSL) != 0 ) {
                capabilities |= MySQLServerCapabilities.SSL;
@@ -452,10 +458,7 @@
                throw new QueryException("Trying to connect with ssl, but ssl not enabled in the server");
            }
 
-           // If a database is given, but createDB is not defined or is false,
-           // then just try to connect to the given database
-           if (database != null && !createDB())
-               capabilities |= MySQLServerCapabilities.CONNECT_WITH_DB;
+        
 
            final MySQLClientAuthPacket cap = new MySQLClientAuthPacket(this.username,
                    this.password,
@@ -496,12 +499,9 @@
            // then just try to create the database and to use it
            if (createDB()) {
                // Try to create the database if it does not exist
-               executeQuery(new MySQLQuery("CREATE DATABASE IF NOT EXISTS " + this.database));
-           }
-           if (database != null && database.length() > 0)
-           {
-               // and switch to this database
-               executeQuery(new MySQLQuery("USE " + database));
+               String quotedDB = MySQLConnection.quoteIdentifier(this.database);
+               executeQuery(new MySQLQuery("CREATE DATABASE IF NOT EXISTS " + quotedDB));
+               executeQuery(new MySQLQuery("USE " + quotedDB));
            }
 
            activeResult = null;

=== modified file 'src/test/java/org/mariadb/jdbc/MySQLDriverTest.java'
--- src/test/java/org/mariadb/jdbc/MySQLDriverTest.java	2013-07-15 17:39:41 +0000
+++ src/test/java/org/mariadb/jdbc/MySQLDriverTest.java	2014-04-17 04:28:40 +0000
@@ -620,4 +620,31 @@
        rs.next();
        assertEquals("'a",rs.getString(1));
     }
+    
+    @Test
+    public void connectToDbWithDashInName() throws Exception {
+    	connection.createStatement().execute("create database `data-base`");
+    	try {
+    		Connection c = DriverManager.getConnection("jdbc:mysql://localhost/data-base?user=root");
+    		assertEquals("data-base",c.getCatalog());
+    		c.close();
+    	}
+    	finally {
+    	   connection.createStatement().execute("drop database `data-base`");
+    	}
+    }
+    
+    @Test
+    public void connectCreateDB() throws Exception {
+    	Connection c = DriverManager.getConnection("jdbc:mysql://localhost/no-such-db?user=root&createDB=true");
+    	try {
+    		assertEquals("no-such-db",c.getCatalog());
+    		c.close();
+    	}
+    	finally {
+    	   connection.createStatement().execute("drop database `no-such-db`");
+    	}
+    }
+    
+    
 }

=== modified file 'src/test/java/org/mariadb/jdbc/SSLValidationTest.java'
--- src/test/java/org/mariadb/jdbc/SSLValidationTest.java	2013-11-14 08:51:54 +0000
+++ src/test/java/org/mariadb/jdbc/SSLValidationTest.java	2014-04-17 04:19:37 +0000
@@ -1,5 +1,7 @@
 package org.mariadb.jdbc;
 
+import static org.junit.Assert.*;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -64,13 +66,14 @@
 	}
 
 	private Connection createConnection(Properties info) throws SQLException {
-		String jdbcUrl = "jdbc:mysql://localhost";
+		String jdbcUrl = "jdbc:mysql://localhost/test";
 		Properties connProps = new Properties(info);
 		connProps.setProperty("user", "root");
 		connProps.setProperty("password", "");
 		return DriverManager.getConnection(jdbcUrl, connProps);
 	}
 
+	
 	public void testConnect(Properties info, boolean sslExpected) throws SQLException {
 		Connection conn = null;
 		Statement stmt = null;
@@ -152,42 +155,15 @@
 
 	@Test
 	public void conc71() throws SQLException {
-    try
-    {
-      Class.forName("org.mariadb.jdbc.Driver").newInstance();
-      String url = "jdbc:mysql://localhost:3306/test";
-
-      JDBCUrl myurl = JDBCUrl.parse(url);
-      Assert.assertEquals("localhost", myurl.getHostname());
-      Assert.assertEquals("test", myurl.getDatabase());
-      Assert.assertEquals(3306, myurl.getPort());
-
-      Properties info = new Properties();
-      ResultSet rs;
-      info.setProperty("user",  "root");
-      info.setProperty("password", "");
-      info.setProperty("serverSslCert", getServerCertificate());
-      info.setProperty("useSSL", "true");
-      Connection conn = DriverManager.getConnection(url, info);
-      Statement st = conn.createStatement();
-
-			// check if SSL matches what is expected
-			rs = st.executeQuery("SHOW STATUS LIKE 'Ssl_cipher'");
-			rs.next();
-			String sslCipher = rs.getString(2);
-			boolean sslActual = sslCipher != null && sslCipher.length() > 0;
-			Assert.assertEquals("SSL connection couldn't be established", true, sslActual);
-
-      rs= st.executeQuery("SELECT DATABASE() AS dbname");
-      String ret= "";
-      while (rs.next())
-      {
-        ret= rs.getString("dbname");
-      }
-      Assert.assertEquals("could not determine default database", "test", ret);
-      conn.close();
-  	} catch (Exception e) {
-      throw new RuntimeException(e);
-    }
+		try  {
+			Properties info = new Properties();
+			info.setProperty("serverSslCert", getServerCertificate());
+			info.setProperty("useSSL", "true");
+			Connection conn = createConnection(info);
+			assertEquals("test",conn.getCatalog());
+			conn.close();
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
 	}
 }

