• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Creating tables from text file

 
Ranch Hand
Posts: 201
2
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, ranchers!

I am trying to create multiple tables from a single textfile called "tables.sql". The tables are marked with a "+" and "|" sign as a delimeter after each
line. In a part of the code I replace the delimeters with the replace method in the String class with some empty space, "" and the "+" sign with a
new line character.

My tables are very basic for this post but longer in real world, they look similar to this in the text file "tables.sql".



Here is my java code for processing the file with the example tables but it doesn't work. I get the error message "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
'CREATE TABLE example2_tbl"



Why is this not working? I don't understand why jdbc can't create multiple tables in one query from a text file and what is needed for it to do so.
I think i must be missing something really obvious here. Any hint or enlightment in this matter is very much appreciated.
Thanks a lot in advance!

Regards,
Robert.





 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Robert Ingmarsson wrote:I don't understand why jdbc can't create multiple tables in one query ...


It's not JDBC - it's MySQL - probably a feature to combat SQL injection.

To disable the feature try setting the allowMultiQueries property to true:
    "jdbc:mysql://localhost:3306/test?allowMultiQueries=true"
reply
    Bookmark Topic Watch Topic
  • New Topic