From 8d56607c54d826c58f6481087207f18eaec112e2 Mon Sep 17 00:00:00 2001 From: "Christian P. MOMON" Date: Wed, 18 Sep 2013 18:03:59 +0200 Subject: [PATCH] Add createSchema method. --- src/fr/devinsy/sikevadb/SQLSikevaDB.java | 32 +++++++++++++++++++ .../fr/devinsy/sikevadb/createSchema.sql | 0 2 files changed, 32 insertions(+) rename scripts/create.sql => src/fr/devinsy/sikevadb/createSchema.sql (100%) diff --git a/src/fr/devinsy/sikevadb/SQLSikevaDB.java b/src/fr/devinsy/sikevadb/SQLSikevaDB.java index 62dbd4c..2ebb6df 100644 --- a/src/fr/devinsy/sikevadb/SQLSikevaDB.java +++ b/src/fr/devinsy/sikevadb/SQLSikevaDB.java @@ -15,6 +15,7 @@ */ package fr.devinsy.sikevadb; +import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -33,6 +34,7 @@ import org.joda.time.DateTime; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import fr.devinsy.util.FileTools; import fr.devinsy.util.StringList; /** @@ -574,6 +576,36 @@ public class SQLSikevaDB implements SikevaDB { return result; } + /** + * This method creates the schema (table) used by SQLSikevaDB. + * + * @throws IOException + * @throws SQLException + */ + public void createSchema() throws IOException, SQLException { + // + String createCommand = FileTools.load(SQLSikevaDB.class.getResource("/fr/devinsy/sikevadb/createSchema.sql")); + + // + Connection connection = null; + PreparedStatement statement = null; + ResultSet resultSet = null; + try { + // + connection = getConnection(); + connection.setAutoCommit(true); + + // + statement = connection.prepareStatement(createCommand); + statement.executeUpdate(); + + connection.commit(); + + } finally { + close(connection, statement, resultSet); + } + } + /** * {@inheritDoc} */ diff --git a/scripts/create.sql b/src/fr/devinsy/sikevadb/createSchema.sql similarity index 100% rename from scripts/create.sql rename to src/fr/devinsy/sikevadb/createSchema.sql