• 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

How 2 create a new DB with MySQL and JDBC

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my project, a requirement is to search if the database exists, if not, the program must create it... I've wrote a generic abstract class that creates a db, i've called DBCreator, then subclasses have the work of create the particular dbase using "CREATE table" SQL sentences... Ok, all of this works, but only if the database exists and has an Url...
Class.forName(driver); //<-- OK
connection = DriverManager.getConnection(url); // No OK
The cuestion is:
How i can create a new database from my application, using MySQL and get the connection to it?
Adios and Thanks
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the problems you are going to have is there is no way to connect to the Database without providing a DB name in the URL as you pointed out. The only way I can suggest you make this work is you can always count on 1 Database being in a MySQL database. It's called mysql. This database actually stores users and permissions, metadata, etc for MySQL. So you can just connect to this database in the initial URL if need be. Keep in mind, allowing your application to connect to this database could be a security risk.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic