Reputation: 93
In Grails 2.5
, i'm doing some DB data insertions at the BootStrap
file , but i'm always getting this error : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'countries_data.sql' at line 1
although when i take this file and run it on my DB it does the insertions successfully.
Here is the BootStrap
code :
def countriesScriptPath = grailsApplication.parentContext.servletContext.getRealPath("/DB_scripts/countries_data.sql")
String sqlFilePathCountries = countriesScriptPath
String sqlStringCountries = new File(sqlFilePathCountries).text
Sql sql = Sql.newInstance(grailsApplication.config.dataSource.url, grailsApplication.config.dataSource.username,
grailsApplication.config.dataSource.password, grailsApplication.config.dataSource.driverClassName)
sql.execute(sqlFilePathCountries)
here are some of the insertion statements :
INSERT INTO countries ( id,version, iso3166_3, name, phonecode) VALUES ( 1,0, "AFG", "Afghanistan", 93); // line 1
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (2, 0, 'ALB', 'Albania', 355);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (3, 0, 'DZA', 'Algeria', 213);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (4, 0, 'ASM', 'American Samoa', 1684);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (5, 0, 'AND', 'Andorra', 376);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (6, 0, 'AGO', 'Angola', 244);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (7, 0, 'AIA', 'Anguilla', 1264);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (8, 0, 'ATA', 'Antarctica', 0);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (9, 0, 'ATG', 'Antigua And Barbuda', 1268);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (10, 0, 'ARG', 'Argentina', 54);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (11, 0, 'ARM', 'Armenia', 374);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (12, 0, 'ABW', 'Aruba', 297);
INSERT INTO countries (id, version, iso3166_3, name, phonecode) VALUES (13, 0, 'AUS', 'Australia', 61);
my DB is MYSQL 5.7.18
, any advice ?
Upvotes: 0
Views: 222
Reputation: 135
Looks like mistyping. Probably, should be
sql.execute(sqlStringCountries)
instead of
sql.execute(sqlFilePathCountries)
Upvotes: 1