0

I need to run a shell script which is executed through java. but when i am running from java it is unable to identify sqlplus command and throwing error for sqlplus as no such file or directory..

My shell Script code is below

function CHECK_CONNECTION {   
    PATH=/data01/u03/TestABC/apps/tech_st/10.1.2/bin:${PATH} ---> Path for  Sqlplus
    WRITE_MESSAGE "Checking database connection details"
    UNAME_PASSWD=${1}

    count=0
        while [ $count -lt 3 ];do
        sqlplus -s ${UNAME_PASSWD}@${DBSID} <<-SQL >> $LOG_FILENAME
            WHENEVER OSERROR EXIT 9;
            WHENEVER SQLERROR EXIT SQL.SQLCODE;
            prompt Connected to the database; 
        quit; SQL

     conn_code=$?

     if [ $conn_code -ne 0 ]; then
        count=`expr $count + 1`
        WRITE_MESSAGE " Trying to connect $count time..\n"
     else
        WRITE_MESSAGE "Database connectivity is working fine.................\n"
        break
     fi
done

if [ $count -eq 3 ]; then

  WRITE_MESSAGE "Database connectivity is not working fine!!!!!check the username/password\n"
  exit 1

fi

I am giving DB details through java UI. Details are reaching correctly in UNIX shell through java.

But same command when I am executing from shell works fine and gets connected to database. So is their any way through which I can get connected to DB without using any client like sqlplus or is their any other way to do such.

any help will be highly appreciated.

6
  • 1
    It might be worth showing some of your code where sqlplus is set up and called. Also, can you show the command line execution and error. Also, what happens if you put the full path to sqlplus in your command. I suspect it's not using $PATH (but could possibly use $ORACLE_HOME in your environment). Commented Feb 13, 2014 at 10:06
  • Incidentally, are you using ProcessBuilder? Commented Feb 13, 2014 at 10:34
  • @wmorrison365 : i have attached code pls check Commented Feb 13, 2014 at 11:30
  • 1
    The real question is: why don't you just do the connection from within your Java program (using JDBC) instead of starting an external application? Commented Feb 13, 2014 at 11:41
  • It should be better to use JDBC driver orafaq.com/wiki/JDBC thin driver does not use Oracle OLI, it is a regular JAVA library Commented Feb 13, 2014 at 11:42

1 Answer 1

1

finally its is solved.

actually when i am running my shell script through java it is unable to recognize the sqlplus command. definition of sqlplus command is present in environment file of UNIX instance but it is unable to execute by it self. so i executed environment file externally through shell script command in my script:

cd ~

. ~/.bash_profile

now after executing it works fine. Thanks for your suggestions friends

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.