How to create a database in Oracle using JDBC?

I want to create a new database on an Oracle server via JDBC. I cannot seem to connect to the database without providing an SID: using a URL like jdbc:oracle:thin:@//[IP]:1521 results in an error of "ORA-12504, TNS:listener was not given the SID in CONNECT_DATA"

Alternatively, if I log into a specific SID, I can run most DDL commands except for CREATE DATABASE foo which fails with an error of "ORA-01100: database already mounted"

How am I supposed to create a database if I cannot connect to the server without specifying a specific database and cannot create a database if I am already logged into a specific database?

Upvotes: 2

Views: 568

Answers (2)

igr
igr

Reputation: 3499

What you need are following commands:

  • CREATE TABLESPACE
  • CREATE USER
  • and few GRANT ... TO ... -- to have rights to connect and create objects, at least

    Upvotes: 0

  • Daniel Alder
    Daniel Alder

    Reputation: 5382

    AFAIK creating a database needs an internal and direct connection which can only be done by logging in directly on the server (normally a user account called 'oracle').

    One reason for that: users are stored in the database itself. No database = no user to connect to by an external client.

    Please also note Justin's comment about oracles database schemas. This is probably what you are looking for

    Upvotes: 0

    Related Questions