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