0

I am currently writing a coursework for my university. The java file I will submit is supposed to interact with a database and our lecturer advised me to use JDBC. My question is (since I could not find anything online) if there is any way JDBC can create a database for me instead of already connecting to an existing database since my lecturer will need to run the project on his PC and I doubt he will set up a database himself first.

Thank you very much for any answer!

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Alex Haller
  • 295
  • 2
  • 17
  • By "create the database" do you mean creating a schema on a MySQL server or instantiating a MySQL server entirely? – CollinD Mar 20 '18 at 20:18
  • @CollinD depends if his lecturer expects a Java program to install MySQL. – Kayaman Mar 20 '18 at 20:20
  • Why don’t you just include a script that sets up the database? – achAmháin Mar 20 '18 at 20:21
  • Well we used Android Studio in a different module and we were able to set up a local database with MySQLite pretty easily so I assumed there is an easy way in eclipse as well. If that doesn't work at all I suppose I will need to include a script. – Alex Haller Mar 20 '18 at 20:22
  • @CollinD I was thinking about any sort of local solution if that exists. – Alex Haller Mar 20 '18 at 20:24
  • @Kayaman I misspoke I guess. Installing MySQL might be a bit much to ask (I've had professors ask worse, but rarely). I was thinking more like an alternative DBMS option like SQLite or h2 or something that wouldn't need a daemon. – CollinD Mar 20 '18 at 20:24

1 Answers1

0

You can execute DDL statements with JDBC, not just DML, so you could execute the statements you need to create your schema on start up.

Alternatively if you are able to use JPA/Hibernate instead of JDBC directly, you can use the hibernate.hbm2ddl.auto property and have it create your schema for you on startup.

Kevin Hooke
  • 2,583
  • 2
  • 19
  • 33