Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an application which has an oracle database, so the installation of the application needs running some oracle commands script files to create the database and perform some DDL operations. Those operations include some table space creation, schema definition etc.

I was trying to prepare an installation wizard using java application. This wizard needs to run these commands. My specific question is: How to run oracle commands script files from inside my java application? I exactly need a java function that takes the sql commands file path as input parameter and executes the commands within the script files from java taking into the eye of consideration that some parameters (e.g. some user-selected names)must be passed to the script file which to be executed

I used to use PL/SQL command line functionality to execute the sql commands as a privileged user.

Here is a section of the file as an example

ACCEPT TS_NAME CHAR PROMPT 'Enter Table Space Name : '
ACCEPT DB_DATAFILE CHAR PROMPT 'Enter DataBase File full path : '
ACCEPT DB_SIZE NUMBER PROMPT 'Enter DataBase File Size (MB) : '
ACCEPT DB_USER CHAR PROMPT 'Enter User Name : '
ACCEPT DB_PASS CHAR PROMPT 'Enter Table Password Name: ' HIDE
ACCEPT DB_TNSNAME CHAR PROMPT 'Enter DATABASE TNSNAME:'
ACCEPT DB_LOG_PATH CHAR PROMPT 'Enter Log File Path : '
PROMPT Create Tablespace
pause Press Return to continue ...
CREATE TABLESPACE &TS_NAME DATAFILE '&DB_DATAFILE' SIZE &DB_SIZE M
AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED LOGGING PERMANENT
EXTENT MANAGEMENT LOCAL AUTOALLOCATE BLOCKSIZE 8K SEGMENT SPACE MANAGEMENT MANUAL;
PROMPT Create User
pause Press Return to continue ...
CREATE USER &DB_USER IDENTIFIED BY &DB_PASS DEFAULT TABLESPACE &TS_NAME PROFILE DEFAULT
QUOTA UNLIMITED ON USERS;
COMMIT;
GRANT CONNECT TO &DB_USER;
GRANT RESOURCE TO &DB_USER;
COMMIT;
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900