1
1
package org .jabref .logic .shared ;
2
2
3
- import java .sql .Connection ;
4
- import java .sql .DriverManager ;
5
- import java .sql .SQLException ;
6
- import java .util .HashSet ;
7
- import java .util .Set ;
8
-
9
3
import org .jabref .logic .l10n .Localization ;
10
4
import org .jabref .logic .shared .exception .InvalidDBMSConnectionPropertiesException ;
11
5
import org .jabref .model .database .shared .DBMSType ;
12
6
import org .jabref .model .database .shared .DatabaseConnection ;
13
-
14
7
import org .slf4j .Logger ;
15
8
import org .slf4j .LoggerFactory ;
16
9
10
+ import java .sql .Connection ;
11
+ import java .sql .DriverManager ;
12
+ import java .sql .SQLException ;
13
+ import java .util .HashSet ;
14
+ import java .util .Set ;
15
+
17
16
public class DBMSConnection implements DatabaseConnection {
18
17
19
18
private static final Logger LOGGER = LoggerFactory .getLogger (DBMSConnection .class );
@@ -38,9 +37,12 @@ public DBMSConnection(DBMSConnectionProperties connectionProperties) throws SQLE
38
37
} catch (SQLException e ) {
39
38
// Some systems like PostgreSQL retrieves 0 to every exception.
40
39
// Therefore a stable error determination is not possible.
41
- LOGGER .error ("Could not connect to database: " + e .getMessage () + " - Error code: " + e .getErrorCode ());
40
+ String message = e .getMessage ();
41
+ int endIndex = message .indexOf ("." ) != -1 ? message .indexOf ("." ) : message .length ();
42
+ String errorMessagee = e .getSQLState ().equals ("01S00" ) ? message .substring (0 , endIndex ) : message ;
43
+ LOGGER .error ("Could not connect to database: " + message + " - Error code: " + e .getErrorCode ());
42
44
43
- throw e ;
45
+ throw new SQLException ( errorMessagee , e ) ;
44
46
}
45
47
}
46
48
0 commit comments