From b25962fcb9ada480dd8e8879b74410188604f47b Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Mon, 17 Aug 2015 08:42:53 +0200 Subject: [PATCH] =?utf8?q?Added=20support=20for=20Long=20and=20currently?= =?utf8?q?=20null=20is=20not=20supported=20Signed-off-by:Roland=20H=C3=A4d?= =?utf8?q?er=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../backend/mysql/MySqlDatabaseBackend.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java index 11f9e20..a0a17c3 100644 --- a/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java +++ b/src/org/mxchange/jcore/database/backend/mysql/MySqlDatabaseBackend.java @@ -118,11 +118,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas this.getLogger().debug("Connection is up, preparing some statements ..."); //NOI18N // Set prepared statement - this.totalRows = connection.prepareStatement("SELECT COUNT(`?`) AS `cnt` FROM `?` LIMIT 1"); - - // Set values in prepared statement - this.totalRows.setObject(1, this.getFrontend().getIdName()); - this.totalRows.setObject(2, this.getTableName()); + this.totalRows = connection.prepareStatement(String.format("SELECT COUNT(`%s`) AS `cnt` FROM `%s` LIMIT 1", this.getFrontend().getIdName(), this.getTableName())); // Trace message this.getLogger().trace("EXIT!"); //NOI18N @@ -348,7 +344,7 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas Object value = valueIterator.next(); //Debug message - this.getLogger().debug(MessageFormat.format("value={0} at index={1}", value, index)); + this.getLogger().debug(MessageFormat.format("index={1} has value={0}", value, index)); // Detect type again if (value instanceof Boolean) { @@ -369,15 +365,24 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas // Found ineteger statement.setInt(index, (int) value); + } else if (value instanceof Long) { + // Debug message + this.getLogger().debug(MessageFormat.format("Setting long value={0} for index={1}", value, index)); + + // Found ineteger + statement.setLong(index, (long) value); } else if (value instanceof Float) { // Debug message this.getLogger().debug(MessageFormat.format("Setting float value={0} for index={1}", value, index)); // Found ineteger statement.setFloat(index, (float) value); + } else if (value == null) { + // Debug message + this.getLogger().warn(MessageFormat.format("Null value in index={0} is not supported (yet)", index)); } else { // Not parseable type - throw new SQLException(MessageFormat.format("Cannot handle value={0} for index={1} in table {2}", value, index, this.getTableName())); + throw new SQLException(MessageFormat.format("Cannot handle value({0})={1} for index={2} in table {3}", value.getClass().getSimpleName(), value, index, this.getTableName())); } // Increment index -- 2.39.5