So i have this pretty large project and i have to create database schemas at various points during runtime and also have connections to point to the newly created schemas. This might seem like havoc but the application is quite large,distributed and multi-agent, so each agent should take care of one such connection.
Again to state the question(s):
1) How can i create a schema at runtime?
2) Inside the java agent how to get the new connection string?
I’ve seen some examples that stated that i should instate a default connection, and change it at runtime using some method that i cannot seem to find now…
P.S. I’d prefer a JDBC solution for this problem 🙂 but if there is an alternative i’d be glad to try it.
It depends a bit on which database you are using. Creating schemas typically involves executing some DDL on a connection where you are logged in with appriopriate privilieges (create schema). On Oracle, you would do something like
Read more here
Connecting to the new schema (in Oracle, user is the same a schema) is just a matter of supplying the new users credentials when opening the connection.
In mysql, you would do something like
Read more here
Connecting to the new schema (in MySQL, database = schema) you add the name of the database to the end of the connection url, like
mysql://myserver/test.