I am new to shell scripting and have less or no idea on this. I have to read a db.properties file which has the database connection details i.e. to which db to connect. Then i have to establish a connection to that database and perform an operation to check the current time.
Below is my db.properties file :-
driverClassName=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@171.01.187.94:1532:DEV
userName=abc
password=abc
Below is my script to call the db.properties file :-
#!/bin/bash
file="./database.properties"
if [ -f "$file" ]
then
echo "$file found."
. $file
echo "User Id = " ${userName}
echo "user password = " ${password}
echo "url = " ${url}
sqlplus -S ${userName}/${password}@${url}
else
echo "$file not found."
fi
But i am getting the below error :-
ERROR: ORA-12154: TNS:could not resolve the connect identifier specified
Could anyone please help on the above issue ?
Don't worry about tnsnames.ora definition, you have all information needed to establish a connection using sqlnet.
Modify your database.properties file as follows:
driverClassName=oracle.jdbc.driver.OracleDriver
url='(description=(address_list=(address=(protocol=TCP)(host=171.01.187.94)(port=1532)))(connect_data=(service_name=DEV)))'
userName=abc
password=abc
And that's it. You don't need to change your script.
#!/bin/bash
file="./database.properties"
if [ -f "$file" ]
then
echo "$file found."
. $file
echo "User Id = " ${userName}
echo "user password = " ${password}
echo "url = " ${url}
sqlplus -S ${userName}/${password}@${url}
else
echo "$file not found."
fi
Note: I assumed that DEV is the database service name, if it's the database SID just modify configuration string as:
driverClassName=oracle.jdbc.driver.OracleDriver
url='(description=(address_list=(address=(protocol=TCP)(host=171.01.187.94)(port=1532)))(connect_data=(sid=DEV)))'
userName=abc
password=abc
Regards
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments