The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to call java prog from shell script kcp_pavan Shell Programming and Scripting 1 03-16-2009 11:28 AM
call constructor of java class in script thebladerunner Shell Programming and Scripting 1 10-21-2008 04:23 PM
Shell script to call multiple java commands vivekdn Shell Programming and Scripting 4 09-03-2008 01:28 AM
How to call Java by using shell script aaabbb123123 Shell Programming and Scripting 2 08-21-2008 03:02 AM
How to call Java class from ksh jyotib Shell Programming and Scripting 3 01-14-2008 02:40 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-28-2009
crackthehit007 crackthehit007 is offline
Registered User
  
 

Join Date: Feb 2009
Location: Pune/Banagalore
Posts: 71
Exclamation how to handle SQL exceptions to call script having args via java ?

Hi,

i want to call shell script via java + in that shell script i m doing some sql operation by connecting to sqlplus .

i want to return 0 if successful exeution of SQL operations else 1 ;

is it possible ?
Code:

#!/bin/sh
Name=$1;
export ORACLE_HOME

$ORACLE_HOME/bin/sqlplus scott@ORA/tiger <<EOF
spool /root/spool1.txt;
select * from tab where tname like '$Name%';
spool off;
EOF

echo "got query data"

exit;


java code

Code:
import java.util.*;
import java.io.*;

public class Script {
	public static void main ( String[] s)
	{
		Runtime r= Runtime.getRuntime();//reference to runtime java environment
		Process P=null;
		String cmd2 = "/root/script.sh school";
		
		try {
			P=r.exec(cmd2);
	
			System.out.println(	P.waitFor());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


is it possible to get info whether SQL query executed properly or not ?
  #2 (permalink)  
Old 09-28-2009
varontron varontron is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 110
you have a few choices:

1) eval spool1.txt in the shell script and return a value based on the result, then check the value in java

2) do step one entirely in java by reading in spool1.txt

3) if you don't actually need your spool.txt for later processing, you could instead nest your query in case statement and return the success/fail as different conditions. you still have to eval the result though.

4) used jdbc to connect to your system and do it all in java.
  #3 (permalink)  
Old 09-29-2009
crackthehit007 crackthehit007 is offline
Registered User
  
 

Join Date: Feb 2009
Location: Pune/Banagalore
Posts: 71
Exclamation

yes.
how shell script script will come to know weather sql thing is executed properly or not ?

can we return variable from shell to java ?

i have sample code in above ..could u plz add up there to achieve this ?
  #4 (permalink)  
Old 09-29-2009
varontron varontron is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 110
eval your spool file in shell script

Code:
#!/bin/sh
Name=$1;
export ORACLE_HOME

$ORACLE_HOME/bin/sqlplus scott@ORA/tiger <<EOF
spool /root/spool1.txt;
select * from tab where tname like '$Name%';
spool off;
EOF

LINECOUNT=`wc -l spool1.txt|cut -f1 d' '`

if [ $LINECOUNT -gt 0 ]
then
  exit 0 #SUCCESS
else
  exit 1 #FAIL
fi

eval your shell output in java (I haven't done the java bit in a while, but try this : )

Code:
   
try {
   P=r.exec(cmd2);
   String exitVal = P.exitValue();
}

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:42 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0