Skip to content

Commit

Permalink
Fixed(?) PostgreSQL problems
Browse files Browse the repository at this point in the history
  • Loading branch information
oscargus committed Dec 6, 2015
1 parent c43389d commit 17372ba
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
69 changes: 34 additions & 35 deletions src/main/java/net/sf/jabref/sql/importer/DbImportAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
*/
Expand Down Expand Up @@ -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<String> v;
Vector<Vector<String>> 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<String> v;
Vector<Vector<String>> 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();
Expand Down

0 comments on commit 17372ba

Please sign in to comment.