vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| |||
| technocrat wrote: > db2 -t -v -f/home.../filename >output_file-name > > I have a java stored procedure..which has to run the above > command...not sure how i can run this command through java.. > any suggestions are appreciated.. System.getRuntime().exec("..."); -- Knut Stolze DB2 Information Integration Development IBM Germany |
| |||
| technocrat wrote: > Doesnt seem like getRuntime method call is present in System > class...gives me an error....any help?? Right, my mistake. Then use the Runtime class. -- Knut Stolze DB2 Information Integration Development IBM Germany |
| |||
| String line; Process p = Runtime.getRuntime().exec("db2cmd /c /w /i db2 -tvf /home/filename.txt >output"); BufferedReader input = new BufferedReader (new InputStreamReader(p.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close(); System.out.println("Output Print done"); When I run this...I get an error saying...db2cmd not found... SQL4302N Procedure or user-defined function "CONTROL.INITTIERONE", specific name "SQL060424133114600" aborted with an exception "db2cmd: not found". SQLSTATE=38501 What might be going wrong??? |
| |||
| db2cmd is for Microsoft Windows systems. You have to use db2profile for linux & unix systems.. Please refer to: http://publib.boulder.ibm.com/infoce...tacpi23104.htm regards, tuarek |
| |||
| tuarek wrote: > db2cmd is for Microsoft Windows systems. You have to use db2profile > for linux & unix systems.. > > Please refer to: > > http://publib.boulder.ibm.com/infoce...ndex.jsp?topic > =/com.ibm.itpc_fabric.doc/btacpi23104.htm Indeed, db2cmd is only used on Windows systems. However, you can't "just" run db2profile on a Linux/UNIX system to the same effect: db2profile is a shell script sets up certain environment variables for the DB2 CLP in the calling shell (DB2DIR, INSTHOME, PATH, CLASSPATH, VWSPATH, LD_LIBRARY_PATH, LIBPATH, and DB2INSTANCE). Java can't run a shell script directly: you'd need to start a shell and run the script within that. However, you'd then need to start the DB2 CLP within that *same* shell (otherwise you'll lose the changes to the environment). Alternatively, I assume Java provides some mechanism of tweaking the environment of a child process when executed, in which case you could avoid db2profile altogether by emulating its actions when executing the CLP (launching the CLP with an appropriately tweaked environment). However, in your OP you mention that this is all part of a stored procedure. In other words, you're trying to execute an SQL script with the DB2 CLP from *within* a Java stored procedure in a DB2 database? That sounds a bit odd to me... What exactly are you trying to accomplish here? It might be there's a simpler way of doing it with an SQL stored procedure. Dave. -- |
| |||
| Dave, I haven't tried yet but don't you think that wouldn't "db2profile && db2 -tvf ..." work? assuming no problem with java program... I believe "&&" will run them sequentially in the same shell call. I'll try. BTW: Running a db2 script from SP didn't make sense to me as well, but then I thought technocrat may be trying to dynamically generate this script with some external interactions. regards, taurek |
| ||||
| tuarek wrote: > Dave, > > I haven't tried yet but don't you think that wouldn't "db2profile && > db2 -tvf ..." work? assuming no problem with java program... > > I believe "&&" will run them sequentially in the same shell call. > I'll try. It will do assuming the Runtime.exec method actually spawns a shell instead of a simple child process (like fork/exec under UNIX, or CreateProcess under Windows). If it doesn't I guess one could use something like "/bin/sh -c db2profile && db2 -tvf ..." instead (as you can probably guess I'm not a Java coder :-) > BTW: Running a db2 script from SP didn't make sense to me as well, but > then I thought technocrat may be trying to dynamically generate this > script with some external interactions. Could well be; it's certainly one situation where such a hack is neeeded. Guess we'll see... Dave. -- |