title: How to execute a script through sqlplus command using jsch?
body: <p>I have an sql script with insert/update queries on my local machine. Then using a java app I am placing this script on a unix machine via ftp. I am then sending sqlplus command using jsch to that machine through the same java app. But I am getting an error : exit-status -- 127. Now, I have found that 127 code is for "Command not found". I checked $PATH on that unix machine and it does include the path to sqlplus. The code I am using is given below where I pass cmd = "sqlplus uname/pwd@databaseURL @insert_script.sql" :</p>
  
  <pre><code>    public static String executeCmd(String cmd){
  
      String user = "username";
      String host = "XX.XXX.XX.XX";
      String owner = new String();
      JSch jsch = new JSch();                
      try {
          Session session = jsch.getSession(user, host, 22);
          //session.setPassword("pwd");
          UserInfo usrInfo = new localUserInfo();
          session.setUserInfo(usrInfo);
          session.connect();
          Channel channel = session.openChannel("exec");
          ((ChannelExec) channel).setCommand(cmd);                        
          channel.setXForwarding(true);
          InputStream in = channel.getInputStream();
          channel.connect();                        
          channel.setInputStream(System.in);
          byte[] tmp = new byte[2048];
          while (true) {
  
              while (in.available() &gt; 0) {
                  int i = in.read(tmp, 0, 2048);
                  if (i &lt; 0)
                      break;
                  owner = (new String(tmp, 0, i));
              }
              if (channel.isClosed()) {
                     owner = "exit-status: "+channel.getExitStatus();
                     break;
              }
              try {
                  Thread.sleep(1000);
              } catch (Exception ee) {
              }
          }
                      System.out.println(owner);
          channel.disconnect();
          session.disconnect();
      } catch (Exception e) {
          e.printStackTrace();
      }
              return owner;
  }
  </code></pre>
  
  <p>Please suggest a way where I dont have to create a separate JDBC connection.</p>