Reputation: 11
Class.forName("oracle.jdbc.driver.OracleDriver");
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","system");
System.out.println("Connection Established");
System.out.println("Creating Database");
stmt=con.createStatement();
String sql="CREATE DATABASE ALAN";
stmt.executeUpdate(sql);
System.out.println("Database Created Successfully");
I am getting this error every time whether Database presents or not:
java.sql.SQLException: ORA-01501: CREATE DATABASE failed ORA-01100: database already mounted
Upvotes: 0
Views: 112
Reputation: 7033
In Oracle, a "database" is a physical instance, including processes, initialization parameter files, redo log files, and data files. It is not the same meaning as "database" in MySQL, SQL Server, or most other databases, where a "database" is synonymous with "schema". In Oracle, "user" and "schema" are synonymous. You are seeing this error because the "xe" database already exists, is mounted and running, and you have connected to it. You cannot issue a "create database" command from a connection to a running database.
See here for examples of "create database" usage in Oracle:
I suspect you are actually looking for the "create user" command, to create a schema within the database to contain objects like tables, indexes, and views, etc.
Upvotes: 2