From 17372ba0b9e43d2238e6955999ca82a8a9d01ab9 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sun, 6 Dec 2015 16:57:05 +0100 Subject: [PATCH] Fixed(?) PostgreSQL problems --- .../sql/exporter/PostgreSQLExporter.java | 7 +- .../jabref/sql/importer/DbImportAction.java | 69 +++++++++---------- 2 files changed, 37 insertions(+), 39 deletions(-) diff --git a/src/main/java/net/sf/jabref/sql/exporter/PostgreSQLExporter.java b/src/main/java/net/sf/jabref/sql/exporter/PostgreSQLExporter.java index 45179617929..f5a43d6da1a 100644 --- a/src/main/java/net/sf/jabref/sql/exporter/PostgreSQLExporter.java +++ b/src/main/java/net/sf/jabref/sql/exporter/PostgreSQLExporter.java @@ -73,11 +73,10 @@ public Connection connectToDB(DBStrings dbstrings) throws Exception { conn.close(); } - try (Connection conn = DriverManager.getConnection(url, dbstrings.getUsername(), dbstrings.getPassword())) { - createPLPGSQLFunction(conn); + Connection conn = DriverManager.getConnection(url, dbstrings.getUsername(), dbstrings.getPassword()); + createPLPGSQLFunction(conn); - return conn; - } + return conn; } private void createPLPGSQLFunction(Connection conn) throws SQLException { diff --git a/src/main/java/net/sf/jabref/sql/importer/DbImportAction.java b/src/main/java/net/sf/jabref/sql/importer/DbImportAction.java index 7f7c86ab438..a7c88e38a42 100644 --- a/src/main/java/net/sf/jabref/sql/importer/DbImportAction.java +++ b/src/main/java/net/sf/jabref/sql/importer/DbImportAction.java @@ -44,7 +44,7 @@ * Created by IntelliJ IDEA. User: alver Date: Mar 27, 2008 Time: 6:09:08 PM To change this template use File | Settings * | File Templates. * - * Jan. 20th Changed to accomodate the new way to connect to DB and also to show the exceptions and to display more than + * Jan. 20th Changed to accommodate the new way to connect to DB and also to show the exceptions and to display more than * one DB imported (by ifsteinm) * */ @@ -137,51 +137,50 @@ private void performImport() { frame.output(Localization.lang("Attempting SQL import...")); DBExporterAndImporterFactory factory = new DBExporterAndImporterFactory(); DBImporter importer = factory.getImporter(dbs.getServerType()); - try (Connection conn = importer.connectToDB(dbs)) { - try (ResultSet rs = SQLUtil.queryAllFromTable(conn, "jabref_database")) { - Vector v; - Vector> matrix = new Vector<>(); - - while (rs.next()) { - v = new Vector<>(); - v.add(rs.getString("database_name")); - matrix.add(v); - } + try (Connection conn = importer.connectToDB(dbs); + ResultSet rs = SQLUtil.queryAllFromTable(conn, "jabref_database")) { + Vector v; + Vector> matrix = new Vector<>(); + + while (rs.next()) { + v = new Vector<>(); + v.add(rs.getString("database_name")); + matrix.add(v); + } - if (!matrix.isEmpty()) { - DBImportExportDialog dialogo = new DBImportExportDialog(frame, matrix, - DBImportExportDialog.DialogType.IMPORTER); + if (!matrix.isEmpty()) { + DBImportExportDialog dialogo = new DBImportExportDialog(frame, matrix, + DBImportExportDialog.DialogType.IMPORTER); - if (dialogo.removeAction) { - String dbName = dialogo.selectedDB; - importer.removeDB(dialogo, dbName, conn, metaData); - performImport(); - } else { - if (dialogo.moreThanOne) { - databases = importer.performImport(dbs, dialogo.listOfDBs); - for (Object[] res : databases) { - database = (BibtexDatabase) res[0]; - metaData = (MetaData) res[1]; - dbs.isConfigValid(true); - } - frame.output(Localization.lang("%0 databases will be imported", - Integer.toString(databases.size()))); - } else { - frame.output(Localization.lang("Importing cancelled")); + if (dialogo.removeAction) { + String dbName = dialogo.selectedDB; + importer.removeDB(dialogo, dbName, conn, metaData); + performImport(); + } else { + if (dialogo.moreThanOne) { + databases = importer.performImport(dbs, dialogo.listOfDBs); + for (Object[] res : databases) { + database = (BibtexDatabase) res[0]; + metaData = (MetaData) res[1]; + dbs.isConfigValid(true); } + frame.output(Localization.lang("%0 databases will be imported", + Integer.toString(databases.size()))); + } else { + frame.output(Localization.lang("Importing cancelled")); } - } else { - JOptionPane.showMessageDialog(frame, - Localization.lang("There are no available databases to be imported"), - Localization.lang("Import from SQL database"), JOptionPane.INFORMATION_MESSAGE); } + } else { + JOptionPane.showMessageDialog(frame, + Localization.lang("There are no available databases to be imported"), + Localization.lang("Import from SQL database"), JOptionPane.INFORMATION_MESSAGE); } } } catch (Exception ex) { String preamble = Localization.lang("Could not import from SQL database for the following reason:"); String errorMessage = SQLUtil.getExceptionMessage(ex); dbs.isConfigValid(false); - JOptionPane.showMessageDialog(frame, Localization.lang(preamble) + '\n' + errorMessage, + JOptionPane.showMessageDialog(frame, preamble + '\n' + errorMessage, Localization.lang("Import from SQL database"), JOptionPane.ERROR_MESSAGE); frame.output(Localization.lang("Error importing from database")); ex.printStackTrace();