diff --git a/CHANGELOG.md b/CHANGELOG.md index 07132ee968bd..142f6a0ad163 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ to [sourceforge feature requests](https://sourceforge.net/p/jabref/features/) by - Fixed [#710](https://github.com/JabRef/jabref/issues/710): Fixed quit behaviour under OSX - Merge from DOI now honors removed fields - Fixed [#778](https://github.com/JabRef/jabref/issues/778): Fixed NPE when exporting to .sql File - +- Fixed [#685](https://github.com/JabRef/jabref/issues/685): Fixed MySQL exporting for more than one entry ### Removed - Fixed [#627](https://github.com/JabRef/jabref/issues/627): The pdf field is removed from the export formats, use the file field diff --git a/src/main/java/net/sf/jabref/sql/DBStrings.java b/src/main/java/net/sf/jabref/sql/DBStrings.java index 396922281366..335767467412 100644 --- a/src/main/java/net/sf/jabref/sql/DBStrings.java +++ b/src/main/java/net/sf/jabref/sql/DBStrings.java @@ -33,6 +33,7 @@ public class DBStrings { private String database; private String username; private String password; + private String dbParameters = ""; private List serverTypes; private boolean isInitialized; @@ -123,6 +124,25 @@ public void isConfigValid(boolean confValid) { this.configValid = confValid; } + /** + * Returns the database parameters set + * @return dbParameters: The concatenated parameters + */ + public String getDbParameters() { + return dbParameters; + } + + /** + * Add server specific database parameter(s)
+ * Multiple parameters must be concatenated in the format
+ * {@code ?Parameter1=value¶meter2=value2} + * @param dbParameter The concatendated parameter + */ + public void setDbParameters(String dbParameters) { + this.dbParameters = dbParameters; + } + + /** * Store these db strings into JabRef preferences. */ @@ -132,4 +152,6 @@ public void storeToPreferences() { Globals.prefs.put(JabRefPreferences.DB_CONNECT_DATABASE, getDatabase()); Globals.prefs.put(JabRefPreferences.DB_CONNECT_USERNAME, getUsername()); } + + } diff --git a/src/main/java/net/sf/jabref/sql/SQLUtil.java b/src/main/java/net/sf/jabref/sql/SQLUtil.java index f99e3a043c39..76adc5ba2bfc 100644 --- a/src/main/java/net/sf/jabref/sql/SQLUtil.java +++ b/src/main/java/net/sf/jabref/sql/SQLUtil.java @@ -228,7 +228,7 @@ public static AutoCloseable processQueryWithResults(Object out, String query) th public static String createJDBCurl(DBStrings dbStrings, boolean withDBName) { String url; url = "jdbc:" + dbStrings.getServerType().toLowerCase() + "://" + dbStrings.getServerHostname() - + (withDBName ? '/' + dbStrings.getDatabase() : ""); + + (withDBName ? '/' + dbStrings.getDatabase() : "") + dbStrings.getDbParameters(); return url; } diff --git a/src/main/java/net/sf/jabref/sql/exporter/MySQLExporter.java b/src/main/java/net/sf/jabref/sql/exporter/MySQLExporter.java index b02284c92ea9..9f8c132b1b67 100644 --- a/src/main/java/net/sf/jabref/sql/exporter/MySQLExporter.java +++ b/src/main/java/net/sf/jabref/sql/exporter/MySQLExporter.java @@ -36,6 +36,7 @@ final public class MySQLExporter extends DBExporter { private static MySQLExporter instance; + private static String optAllowMultiQueries = "?allowMultiQueries=true"; private MySQLExporter() { @@ -55,15 +56,19 @@ public static MySQLExporter getInstance() { @Override public Connection connectToDB(DBStrings dbstrings) throws Exception { this.dbStrings = dbstrings; + + dbStrings.setDbParameters(optAllowMultiQueries); String url = SQLUtil.createJDBCurl(dbstrings, false); String drv = "com.mysql.jdbc.Driver"; + Class.forName(drv).newInstance(); Connection conn = DriverManager.getConnection(url, dbstrings.getUsername(), dbstrings.getPassword()); SQLUtil.processQuery(conn, "CREATE DATABASE IF NOT EXISTS `" + dbStrings.getDatabase() + '`'); - SQLUtil.processQuery(conn, "USE `" + dbStrings.getDatabase() + '`'); + + conn.setCatalog(dbStrings.getDatabase()); return conn; }