![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 ? |
|
||||
|
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. |
|
||||
|
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 ? |
|
||||
|
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();
}
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|