harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r450416 - in /incubator/harmony/enhanced/classlib/trunk/modules/sql/src: main/java/java/sql/DriverManager.java test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
Date Wed, 27 Sep 2006 12:17:51 GMT
Author: tellison
Date: Wed Sep 27 05:17:49 2006
New Revision: 450416

URL: http://svn.apache.org/viewvc?view=rev&rev=450416
Log:
Apply patch HARMONY-1597 ([classlib][sql] In some situation, SQLState is not set when a SQLException
is thrown in DriverManager)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java?view=diff&rev=450416&r1=450415&r2=450416
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/java/sql/DriverManager.java
Wed Sep 27 05:17:49 2006
@@ -160,9 +160,12 @@
      */
     public static Connection getConnection(String url, Properties info)
             throws SQLException {
+        // 08 - connection exception
+        // 001 - SQL-client unable to establish SQL-connection
+        String sqlState = "08001";
         if (url == null) {
             // sql.5=The url cannot be null
-            throw new SQLException(Messages.getString("sql.5")); //$NON-NLS-1$
+            throw new SQLException(Messages.getString("sql.5"), sqlState); //$NON-NLS-1$
         }
         synchronized (theDriverSet) {
             /*
@@ -181,7 +184,7 @@
         }
         // If we get here, none of the drivers are able to resolve the URL
         // sql.6=No suitable driver
-        throw new SQLException(Messages.getString("sql.6")); //$NON-NLS-1$
+        throw new SQLException(Messages.getString("sql.6"), sqlState); //$NON-NLS-1$ //$NON-NLS-2$
     }
 
     /**
@@ -242,7 +245,9 @@
         }
         // If no drivers understand the URL, throw an SQLException
         // sql.6=No suitable driver
-        throw new SQLException(Messages.getString("sql.6")); //$NON-NLS-1$
+        //SQLState: 08 - connection exception
+        //001 - SQL-client unable to establish SQL-connection
+        throw new SQLException(Messages.getString("sql.6"), "08001"); //$NON-NLS-1$
     }
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java?view=diff&rev=450416&r1=450415&r2=450416
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/sql/src/test/java/org/apache/harmony/sql/tests/java/sql/DriverManagerTest.java
Wed Sep 27 05:17:49 2006
@@ -215,6 +215,27 @@
 			} // end try
 		} // end for
 	} // end method testGetConnectionString()
+    
+    /**
+     * @tests java.sql.DriverManager#getConnection(String, Properties)
+     */
+    public void test_getConnection_LStringLProperties() {
+        try {
+            DriverManager.getConnection("fff", //$NON-NLS-1$
+                    new Properties());
+            fail("Should throw SQLException.");
+        } catch (SQLException e) {
+            assertEquals("08001", e.getSQLState()); //$NON-NLS-1$
+        }
+        
+        try {
+            DriverManager.getConnection(null, 
+                    new Properties());
+            fail("Should throw SQLException.");
+        } catch (SQLException e) {
+            assertEquals("08001", e.getSQLState()); //$NON-NLS-1$
+        }
+    }
 
 	/*
 	 * Class under test for Connection getConnection(String, Properties)
@@ -352,15 +373,18 @@
 			try {
 				Driver invalidDriver = DriverManager.getDriver(invalidURLs[i]);
 			} catch (SQLException e) {
-				assertTrue(true);
-				// System.out.println("DriverManagerTest: getDriver failed for
-				// invalid driver");
-				// System.out.println("DriverManagerTest: exception message = "
-				// + e.getMessage() );
-				assertTrue(e.getMessage().equals(exceptionMsg1));
+                assertEquals("08001", e.getSQLState());
+				assertEquals(exceptionMsg1, e.getMessage());
 			} // end try
 		} // end for
 
+        try {
+            Driver invalidDriver = DriverManager.getDriver(null);
+        } catch (SQLException e) {
+            assertEquals("08001", e.getSQLState());
+            assertEquals(exceptionMsg1, e.getMessage());
+        } // end try
+        
 	} // end method testGetDriver()
 
 	public void testGetDrivers() {



Mime
View raw message