Possible? output a string from a java program into a running program
I'm not sure if it is plausible, but this is my dilemma. My java program searches for street names in a specific region, then outputs the nearest street. I would like to synch this up with Google Earth, and output the street name into it, so it would go ahead and be able to search it right away. Is this possible, or should I attempt some other route?
Check out my runCmd method. It gives an example of running another program and listening for the output. I built this to run javac and show the output in my custom editor.
You'll see some classes in here that are not standard java classes, in particular InfoFetcher. Don't worry, this is just a utility I wrote for convenient handling of inputstreams. You can handle the inputstreams without it, but if you really want it, it's probably posted somewhere in these forums.
private void runCmd(String cmd) {
try {
System.out.println("cmd: " + cmd);
Process p = Runtime.getRuntime().exec(cmd);
InputStream stream = p.getInputStream();
InputStream stream2 = p.getErrorStream();
InfoFetcher info = new InfoFetcher(stream, new byte[512], 500);
InputStreamListener l = new InputStreamListener() {
int currentLength = 0;
public void gotAll(InputStreamEvent ev) {}
public void gotMore(InputStreamEvent ev) {
String str = new String(ev.buffer, currentLength, ev.getBytesRetrieved());
currentLength = ev.getBytesRetrieved();
System.out.print(str);
info.addInputStreamListener(l);
Thread t = new Thread(info);
t.start();
InfoFetcher info2 = new InfoFetcher(stream2, new byte[512], 500);
InputStreamListener l2 = new InputStreamListener() {
int currentLength = 0;
public void gotAll(InputStreamEvent ev) {}
public void gotMore(InputStreamEvent ev) {
String str = new String(ev.buffer, currentLength, ev.getBytesRetrieved());
currentLength = ev.getBytesRetrieved();
System.out.print("(Error) " + str);
info2.addInputStreamListener(l2);
Thread t2 = new Thread(info2);
t2.start();
catch (IOException iox) {
iox.printStackTrace();
}
Similar Messages
-
Possibility of calling standard actions from a java program
Hi ,
I am working for a project where customer wants to have option of saving orders as draft only and later convert to order if need be. However since we do not want many drafts to reside on server there is a need to delete these at a specified time. For draft orders I am using order templates since they stay in the database without getting converted to orders. Now I do not know how to go about the deletion part.
i need to write a program that would run on the server and which would fetch the templates (drafts) that have been created till a particular time and call the delete action of the template. Now the question is how do i call these actions from a java program where this java program will have to run on the server end (ie will be a backend process).
Please suggest.
Thanks
Roopalihello roopali,
you can create a separate thread that will run your
code that will check for stale drafts and delete them.
it is just like a session management program but here
we will be looking over the drafts and not the session
objects.
now if you want the invocation of the action from another
program, a socket program would suffice but opening ports
will cause you network connections thru firewall.
if you can make use of HTTP servlet as your service
provider e.g., you can then just pass some action params
to invoke it.
regards
jo -
Running curl command from a java program using Runtime.getRuntime.exec
for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
Any ideas on why this might be happening?thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
I am using 7.15 in my system.
Below is the code which errors out.
public int execCurlCmd(String command)
String s = null;
try {
// run the Unix "ps -ef" command
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));
// read the output from the command
System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
return(0);
catch (IOException e) {
System.out.println("exception happened - here's what I know: ");
e.printStackTrace();
return(-1);
} -
How can I pass system commands from a java program? Urgent!
hi,
I have been trying this out since a long time. How do I send system commands to command.com or cmd.exe from a java program and an output of the executed command back to the java application.
If u have any idea, or have any information about the kind os application reply back.
Thanks
Deepa DatarThis is the code which I tried, but it displays only the title of MS-DOS, something like " Microsoft Corp...etc ". But doesn't take any input, and the subprocess(cmd.exe) hangs.
import java.io.*;
public class cmddemo2
public static void main(String arg[])
try
System.out.println("cmd");
Process p=Runtime.getRuntime().exec("cmd.exe");
DataInputStream din=new DataInputStream(p.getInputStream());
DataOutputStream dout=new DataOutputStream(p.getOutputStream());
System.out.println("after streams");
String s;
dout.writeChars("type cmddemo2.java");
while((s=din.readLine())!="\n")
System.out.println(s);
dout.writeChars("dir");
String s1;
while((s1=din.readLine())!="\n")
System.out.println(s1);
System.out.println("over");
catch(Exception e)
{ System.out.println("Exception : "+e); -
How to launch executable from a java program
In c++ we can use a function WinExec to execute exe from a c++ program.
Is there a way to launch executables using java program. Lets say I have one executable with name "myexecutable.exe" and a java program "myprogram.java". How can I launch "myexecutable.exe" from the java program.
Is there a way to do this in Java?
Vijay>>
class LoadExecutable
static void loadProcess()
Runtime r = Runtime.getRuntime();
Process p = r.exex("winword.exe");
public static void main(String args[])
loadProcess();
}Regards
- ManikantanBoth of these aren't good ideas - neither of them
deals with the input or output streams at all.
Everyone who's posted to this thread should read this.
None of you knows how to use Runtime.exec properly:
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-t
aps.html
MOD
Thanks for the tips
-Regards
Manikantan -
How to start java.exe from a java program in windows ?
Hi,
I did like to know, if its possible to run java.exe from a java program on windows ? The java.exe should be visible from checking the processes that are currently running using the Task Manager on windows.Runtime.getRuntime().exec("java Sample");
-
How to have an Oracle procedure send and receive value from a java program.
The below procedure is place inside a package. This procedure "get_extract_ready_headers " is selecting columns store_number, terminal_number, tran_number, tran_date, cust_id from the source REX_HEAD_EXTRACT table. This information is selected into a ref cursor. The data has cust_id field which is encrypted. How do I modify the procedure get_extract_ready_headers and accomplish 2 things?
1. Make this procedure to read the "cust_id" value from the source table and send the value to a Java program "getheaderinfo" (this java program decrypts the cust_id field).
2. When we get the unencrypted value back from the Java program, make the procedure accept this decrypted value and use it to update CUST_ID value in the target table TRAN_HEAD table. I am using Oracle 11.2.0.2, and TOAD 10.5.1.3.
-- Procedural code
PROCEDURE get_extract_ready_headers (p_records OUT SYS_REFCURSOR)
IS
BEGIN
OPEN p_records FOR
SELECT store_number, terminal_number, tran_number, tran_date, cust_id FROM REX_HEAD_EXTRACT;
END;--Table Structure for source table REX_HEAD_EXTRACT
CREATE TABLE REX_HEAD_EXTRACT
REX_SEQ_NBR NUMBER(20),
REVISION_NUMBER NUMBER,
DAY NUMBER(3),
RESA_TRAN_SEQ_NO NUMBER(20),
BUSINESS_DATE DATE,
TRAN_SEQ_NBR NUMBER(12),
ORG_NUMBER NUMBER,
STORE_NUMBER NUMBER,
TRAN_DATE DATE,
TERMINAL_NUMBER NUMBER,
TRAN_NUMBER NUMBER,
TRAN_TIME DATE,
BATCH_NUMBER VARCHAR2(8 BYTE),
BATCH_TYPE VARCHAR2(4 BYTE),
TRAN_TYPE VARCHAR2(4 BYTE),
SUB_TRAN_TYPE VARCHAR2(4 BYTE),
CLERK_CODE VARCHAR2(15 BYTE),
TRAN_TAXABLE_AMOUNT NUMBER(12,2),
TRAN_TAX_TOTAL NUMBER(12,2),
TRAN_GROSS_TOTAL NUMBER(12,2),
COUP_TOTAL NUMBER(9,2),
MKD_TOTAL NUMBER(9,2),
EMPLOYEE_NUMBER VARCHAR2(15 BYTE),
EMPLOYEE_NAME VARCHAR2(40 BYTE),
TRAN_ALTTAXABLE_AMOUNT NUMBER(12,2),
TRAN_ALTTAX_TOTAL NUMBER(12,2),
SALE_AMOUNT NUMBER(9,2),
RETURN_AMOUNT NUMBER(9,2),
RETURNED_AMOUNT NUMBER(9,2),
NETCASH NUMBER(12,2),
TENDER_CODE VARCHAR2(4 BYTE),
MULT_RCPT VARCHAR2(1 BYTE),
SPLIT_TENDER VARCHAR2(1 BYTE),
RTN_WITH_PURCHASE VARCHAR2(1 BYTE),
RTN_WITH_RCPT VARCHAR2(1 BYTE),
REASON_CODE VARCHAR2(4 BYTE),
PASSWORD VARCHAR2(10 BYTE),
RINGTIME DATE,
CUST_NUMBER VARCHAR2(12 BYTE),
CUST_ID VARCHAR2(50 BYTE),
ZIP_CODE NUMBER,
POSTAL_CODE VARCHAR2(9 BYTE),
PV_TIME_LAPSE NUMBER,
ORIG_STORE_NBR NUMBER,
ORIG_TRAN_DATE DATE,
ORIG_TRAN_TYPE VARCHAR2(4 BYTE),
ORIG_TERM_NBR NUMBER,
ORIG_TRAN_NBR NUMBER,
ORIG_SALE_AMT NUMBER(12,2),
ORIG_TENDER_CODE VARCHAR2(4 BYTE),
ORIG_CLERK_CODE VARCHAR2(15 BYTE),
PREV_TRAN_TYPE VARCHAR2(4 BYTE),
PREV_SUB_TRAN_TYPE VARCHAR2(4 BYTE),
GIFT_REGISTRY_ID VARCHAR2(25 BYTE),
NO_OF_ITEMS NUMBER,
TAX_EXEMPT_ID VARCHAR2(18 BYTE),
TRAN_RINGTIME NUMBER,
AUDITED VARCHAR2(1 BYTE),
BATCH_VERSION NUMBER(9,2),
BATCH_SOURCE VARCHAR2(5 BYTE),
CREATE_DATE DATE,
CREATE_ID VARCHAR2(32 BYTE),
CREATE_PROC VARCHAR2(32 BYTE),
MOD_DATE DATE,
MOD_ID VARCHAR2(32 BYTE),
MOD_PROC VARCHAR2(32 BYTE),
TERMINAL_GROUP NUMBER,
USER_DEF_1 NUMBER,
USER_DEF_2 NUMBER,
USER_DEF_3 NUMBER,
USER_DEF_4 NUMBER(12,2),
USER_DEF_5 NUMBER(12,2),
USER_DEF_6 NUMBER(12,2),
USER_DEF_7 VARCHAR2(50 BYTE),
USER_DEF_8 VARCHAR2(50 BYTE),
USER_DEF_9 VARCHAR2(50 BYTE),
MANAGER_NUMBER VARCHAR2(15 BYTE),
MANAGER_REASON_CODE VARCHAR2(10 BYTE),
MANAGER_SWIPED VARCHAR2(1 BYTE),
PHONE_NO NUMBER(11),
KCPOS_KTH_USER_101 NUMBER,
KCPOS_KTH_USER_102 NUMBER,
KCPOS_KTH_USER_103 NUMBER,
KCPOS_KTH_USER_104 NUMBER,
KCPOS_KTH_USER_105 NUMBER,
KCPOS_KTH_USER_106 NUMBER,
KCPOS_KTH_USER_107 NUMBER,
KCPOS_KTH_USER_108 NUMBER,
KCPOS_KTH_USER_109 NUMBER,
KCPOS_KTH_USER_110 NUMBER,
KCPOS_KTH_USER_201 NUMBER(12,2),
KCPOS_KTH_USER_202 NUMBER(12,2),
KCPOS_KTH_USER_203 NUMBER(12,2),
KCPOS_KTH_USER_204 NUMBER(12,2),
KCPOS_KTH_USER_205 NUMBER(12,2),
KCPOS_KTH_USER_206 NUMBER(12,2),
KCPOS_KTH_USER_207 NUMBER(12,2),
KCPOS_KTH_USER_208 NUMBER(12,2),
KCPOS_KTH_USER_209 NUMBER(12,2),
KCPOS_KTH_USER_210 NUMBER(12,2),
KCPOS_KTH_USER_301 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_302 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_303 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_304 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_305 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_306 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_307 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_308 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_309 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_310 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_401 DATE,
KCPOS_KTH_USER_402 DATE,
KCPOS_KTH_USER_403 DATE,
DISC_TOTAL NUMBER(9,2)
CREATE INDEX REX_HEAD_EXTRACT_NDX ON REX_HEAD_EXTRACT
(REX_SEQ_NBR, REVISION_NUMBER, STORE_NUMBER, TRAN_DATE, TERMINAL_NUMBER, TRAN_NUMBER)-- Create table DDL for target table TRAN_HEAD
CREATE TABLE NAVISTOR.KCPOS_TRAN_HEADER_BASE
TRAN_SEQ_NBR NUMBER(12),
ORG_NUMBER NUMBER,
STORE_NUMBER NUMBER,
TRAN_DATE DATE,
TERMINAL_NUMBER NUMBER,
TRAN_NUMBER NUMBER,
TRAN_TIME DATE,
BATCH_NUMBER VARCHAR2(8 BYTE),
BATCH_TYPE VARCHAR2(4 BYTE),
TRAN_TYPE VARCHAR2(4 BYTE),
SUB_TRAN_TYPE VARCHAR2(4 BYTE),
CLERK_CODE VARCHAR2(15 BYTE) NOT NULL,
TRAN_TAXABLE_AMOUNT NUMBER(12,2),
TRAN_TAX_TOTAL NUMBER(12,2),
TRAN_GROSS_TOTAL NUMBER(12,2),
COUP_TOTAL NUMBER(9,2),
MKD_TOTAL NUMBER(9,2),
EMPLOYEE_NUMBER VARCHAR2(15 BYTE),
EMPLOYEE_NAME VARCHAR2(40 BYTE),
TRAN_ALTTAXABLE_AMOUNT NUMBER(12,2),
TRAN_ALTTAX_TOTAL NUMBER(12,2),
SALE_AMOUNT NUMBER(9,2),
RETURN_AMOUNT NUMBER(9,2),
RETURNED_AMOUNT NUMBER(9,2),
NETCASH NUMBER(12,2),
TENDER_CODE VARCHAR2(4 BYTE),
MULT_RCPT VARCHAR2(1 BYTE),
SPLIT_TENDER VARCHAR2(1 BYTE),
RTN_WITH_PURCHASE VARCHAR2(1 BYTE),
RTN_WITH_RCPT VARCHAR2(1 BYTE),
REASON_CODE VARCHAR2(4 BYTE),
PASSWORD VARCHAR2(10 BYTE),
RINGTIME DATE,
CUST_NUMBER VARCHAR2(12 BYTE),
CUST_ID VARCHAR2(50 BYTE) ENCRYPT USING 'AES256' NO SALT,
ZIP_CODE NUMBER,
POSTAL_CODE VARCHAR2(9 BYTE),
PV_TIME_LAPSE NUMBER,
ORIG_STORE_NBR NUMBER,
ORIG_TRAN_DATE DATE,
ORIG_TRAN_TYPE VARCHAR2(4 BYTE),
ORIG_TERM_NBR NUMBER,
ORIG_TRAN_NBR NUMBER,
ORIG_SALE_AMT NUMBER(12,2),
ORIG_TENDER_CODE VARCHAR2(4 BYTE),
ORIG_CLERK_CODE VARCHAR2(15 BYTE),
PREV_TRAN_TYPE VARCHAR2(4 BYTE),
PREV_SUB_TRAN_TYPE VARCHAR2(4 BYTE),
GIFT_REGISTRY_ID VARCHAR2(25 BYTE),
NO_OF_ITEMS NUMBER,
TAX_EXEMPT_ID VARCHAR2(18 BYTE),
TRAN_RINGTIME NUMBER,
AUDITED VARCHAR2(1 BYTE),
BATCH_VERSION NUMBER(9,2),
BATCH_SOURCE VARCHAR2(5 BYTE),
CREATE_DATE DATE,
CREATE_ID VARCHAR2(32 BYTE),
CREATE_PROC VARCHAR2(32 BYTE),
MOD_DATE DATE,
MOD_ID VARCHAR2(32 BYTE),
MOD_PROC VARCHAR2(32 BYTE),
TERMINAL_GROUP NUMBER,
USER_DEF_1 NUMBER,
USER_DEF_2 NUMBER,
USER_DEF_3 NUMBER,
USER_DEF_4 NUMBER(12,2),
USER_DEF_5 NUMBER(12,2),
USER_DEF_6 NUMBER(12,2),
USER_DEF_7 VARCHAR2(50 BYTE),
USER_DEF_8 VARCHAR2(50 BYTE),
USER_DEF_9 VARCHAR2(50 BYTE),
MANAGER_NUMBER VARCHAR2(15 BYTE),
MANAGER_REASON_CODE VARCHAR2(10 BYTE),
MANAGER_SWIPED VARCHAR2(1 BYTE),
PHONE_NO NUMBER(11),
KCPOS_KTH_USER_101 NUMBER,
KCPOS_KTH_USER_102 NUMBER,
KCPOS_KTH_USER_103 NUMBER,
KCPOS_KTH_USER_104 NUMBER,
KCPOS_KTH_USER_105 NUMBER,
KCPOS_KTH_USER_106 NUMBER,
KCPOS_KTH_USER_107 NUMBER,
KCPOS_KTH_USER_108 NUMBER,
KCPOS_KTH_USER_109 NUMBER,
KCPOS_KTH_USER_110 NUMBER,
KCPOS_KTH_USER_201 NUMBER(12,2),
KCPOS_KTH_USER_202 NUMBER(12,2),
KCPOS_KTH_USER_203 NUMBER(12,2),
KCPOS_KTH_USER_204 NUMBER(12,2),
KCPOS_KTH_USER_205 NUMBER(12,2),
KCPOS_KTH_USER_206 NUMBER(12,2),
KCPOS_KTH_USER_207 NUMBER(12,2),
KCPOS_KTH_USER_208 NUMBER(12,2),
KCPOS_KTH_USER_209 NUMBER(12,2),
KCPOS_KTH_USER_210 NUMBER(12,2),
KCPOS_KTH_USER_301 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_302 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_303 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_304 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_305 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_306 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_307 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_308 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_309 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_310 VARCHAR2(50 BYTE),
KCPOS_KTH_USER_401 DATE,
KCPOS_KTH_USER_402 DATE,
KCPOS_KTH_USER_403 DATE,
DISC_TOTAL NUMBER(9,2),
RTA_RTN_AUTCOD VARCHAR2(4 BYTE),
RTA_RTN_COMMID NUMBER,
RTA_RTN_EVNTID NUMBER,
RTA_RTN_QTY NUMBER,
RTA_RTN_RCPT_SCAN VARCHAR2(1 BYTE),
RTA_RTN_REFUND_AMT NUMBER(9,2),
RTA_RTN_TYPE_CODE VARCHAR2(4 BYTE),
RTA_RTN_WITH_RCPT VARCHAR2(1 BYTE),
RTA_RTN_COUNT INTEGER,
SDEDVAL1 VARCHAR2(50 BYTE)
)--sample data
REX_SEQ_NBR,REVISION_NUMBER,DAY,RESA_TRAN_SEQ_NO,BUSINESS_DATE,TRAN_SEQ_NBR,ORG_NUMBER,STORE_NUMBER,TRAN_DATE,TERMINAL_NUMBER,
TRAN_NUMBER,TRAN_TIME
478,1,11,12024005,6/11/2012,,1,692,6/11/2012,155,5,6/11/2012 12:57:17 PM,
479,1,11,12024006,6/11/2012,,1,692,6/11/2012,155,6,6/11/2012 2:01:51 PM,
480,1,11,12024007,6/11/2012,,1,692,6/11/2012,155,7,6/11/2012 2:47:10 PMAssuming that SomeJavePgm is a Java stored function (not a Java program running outside the database) and that it takes as a parameter whatever data type CUST_ID is in TABLE_A (hopefully RAW but potentially VARCHAR2) and returns a string, you would call it just as you would a PL/SQL stored function
INSERT INTO table_b( cust_id, <<other columns>> )
SELECT SomeJavaPgm( a.cust_id ), <<other columns>>
FROM table_a aIf SomeJavePgm is not a Java stored procedure, calling it from PL/SQL becomes much more complicated. You would need whatever machine hosts this program to expose an appropriate API (for example, a web service interface) that you could invoke via UTL_HTTP). You'd need to tell us what that API was, however.
Justin -
How to execute unix command from the Java program running on Windows
Hello,
I need to
1. Execute a unix shell script from a Java program running on the Windows.
2. I also need to capture the output of this shell script in my program.
Please suggest me how to achieve this.
Thanks in Advance.Hi...
Something is missing here
If you want to execute a shell script in windows that not posible unless you find or develop a unix shell script parser for windows.
But if you are trying the execute a unix shell script on a remote unix computer from your java program running on a windows platform you can do that by logging on to the UNIX terminal which is running on port 23 I think.
You can test this using telnet tool on windows
just type on command prompt
telnet <ip of the unix pc> <port number this case 23>
you should get the unix terminal. If that works you can do the same through java or you can directly conect to port 23 of that pc using sockets that way your program will be platform independant -
How can I execute a batch file from my java program
Hi,
Can someone help me or direct me to a link,
How can I execute a DOS batch file from my java program?
ThanksYou will need to grab a handle to the process's
outputstream so u can see its output.The OP didn't mention any output from any batch file;
nor any input for that
matter,so lets not complicate matters here for now
ok?Actually I think this is essential to see whether it works or not. It's either that or do some manual check to see whether it ran, which is not exactly elegant, and in some cases this may not be easier than simply writing the output stream code, or in fact it may be impossible to check manually.
I'm sure it wasn't intentional that your post appeared to be bristling with attitude. -
Calling servlet from a java program
Hi
I need to call a servlet's doPost() method from a java program. I have a specific situation, where I need to call servlet from a java program. DUring this call I need to pass a file and two string to the servlet. Servelt after receiving the file and string uploads the file to the server at a specified location. I am stuck up as how to call servlet from a java program instead of a HTML or JSP.
Can anyone help me to start with this.
any suggestion is welcome.You have to establish a URLConnection with servlet from your java program.
URL servletURL = new URL("http://localhost:8080/Myservlet?str1=abc&str2=def");
URLConnection servletConnection = servletURL.openConnection();you can get the objectOutputStream
ObjectOutputStream oos = new ObjectOutputStream (servletConnection.getOutputStream());
oos.writeObject(your file object);-------------------------------------------------
In the servlet u can get the strings using request.getParameter("str1");
In the servlet u can get the strings using request.getParameter("str2");
file = new ObjectInputStream (request.getInputStream()).readObject()a lot of resources are available on this ...
hope this helps :) -
Cannot call ANY stored functions from my Java program
My problem is that I cannot call ANY stored procedure from my Java
program. Here is the code for one of my stored procedures which runs
very well in PL/SQL:
PL/SQL code:
CREATE OR REPLACE PACKAGE types AS
TYPE cursorType IS REF CURSOR;
END;
CREATE OR REPLACE FUNCTION list_recs (id IN NUMBER)
RETURN types.cursorType IS tracks_cursor types.cursorType;
BEGIN
OPEN tracks_cursor FOR
SELECT * FROM accounts1
WHERE id = row_number;
RETURN tracks_cursor;
END;
variable c refcursor
exec :c := list_recs(11)
SQL> print c
COLUMN1 A1 ROW_NUMBER
rec_11 jacob 11
rec_12 jacob 11
rec_13 jacob 11
rec_14 jacob 11
rec_15 jacob 11
Here is my Java code:
import java.sql.*;
import java.io.*;
import oracle.jdbc.driver.*;
class list_recs
public static void main(String args[]) throws SQLException,
IOException
String query;
CallableStatement cstmt = null;
ResultSet cursor;
// input parameters for the stored function
String user_name = "jacob";
// user name and password
String user = "jnikom";
String pass = "jnikom";
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
try { Class.forName ("oracle.jdbc.driver.OracleDriver"); }
catch (ClassNotFoundException e)
{ System.out.println("Could not load driver"); }
Connection conn =
DriverManager.getConnection (
"jdbc:oracle:thin:@10.52.0.25:1521:bosdev",user,pass);
try
String sql = "{ ? = call list_recs(?) }";
cstmt = conn.prepareCall(sql);
// Use OracleTypes.CURSOR as the OUT parameter type
cstmt.registerOutParameter(1, OracleTypes.CURSOR);
String id = "11";
cstmt.setInt(2, Integer.parseInt(id));
// Execute the function and get the return object from the call
cstmt.executeQuery();
ResultSet rset = (ResultSet) cstmt.getObject(1);
while (rset.next())
System.out.print(rset.getString(1) + " ");
System.out.print(rset.getString(2) + " ");
System.out.println(rset.getString(3) + " ");
catch (SQLException e)
System.out.println("Could not call stored function");
e.printStackTrace();
return;
finally
cstmt.close();
conn.close();
System.out.println("Stored function was called");
Here is how I run it, using Win2K and Oracle9 on Solaris:
C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>java
list_recs
Could not call stored function
java.sql.SQLException: ORA-00600: internal error code, arguments:
[ttcgcshnd-1], [0], [], [], [], [], [], []
at
oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.fetch(TTC7Protocol.java:889)
at
oracle.jdbc.driver.OracleStatement.<init>(OracleStatement.java:490)
at
oracle.jdbc.driver.OracleStatement.getCursorValue(OracleStatement.java:2661)
at
oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4189)
at
oracle.jdbc.driver.OracleStatement.getObjectValue(OracleStatement.java:4123)
at
oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:541)
at list_recs.main(list_recs.java:42)
C:\Jacob\Work\Java\Test\Vaultus\Oracle9i\FunctionReturnsResultset>
Any help is greatly appreciated,
Jacob NikomThank you for your suggestion.
I tried it, but got the same result. I think the difference in the syntax is due to the Oracle versus SQL92 standard
conformance. Your statament is the Oracle version and mine is the SQL92. I think both statements are acceptable
by the Oracle.
Regards,
Jacob Nikom -
How to display a oracle table from a java program?
How to display a oracle table from a java program.
Hello friends, I have written a Java program, using oracle 10g as backend.
I want to display a oracle table as output. Im not getting how to display oracle table as a output table.. Pls help me
Thank youjayanthds, you're not going to get a satisfactory
answer to this here. it's too big a task to justbe
quickly outlined in a forum - the reply "all youneed
to do is to query you table and return it asJTable"
is worthless, for example, since the solution to
any problem can be distilled to such a
soundbite, if need be. doesn't make the solutionany
simpler
essentially you're asking "how do I write adatabase
application?". all you'll get is snippets of code
that, when fitted together, will eventually helpyou
do this, but you'll spend days and days comingback
saying "right, I've done that, now what?" until
either you or the forum gets frustrated with the
whole affair and the process stops
there are entire books written about this subject,
and countless tutorials and guides on theinternet.
you're better off going down that routehehehe.well, it's true! I used to have a manager that would outline the solution to a problem in a few lines of pseudocode, and then firmly believe that the actual solution would be just as brief and simple. shame his pseudocode included such lofty abstractions as "reformat all data" -
How to run a openssl command from a java program
Hi All
Please suggest on how to run a openssl command from a java program.
I am using this
Runtime runtime = Runtime.getRuntime();
runtime.exec("openssl pkcs8 -inform der -nocrypt test.der result.pem");
This is suppose to take test.der as input and create result.pem.
There are no errors but the file result.pem isnt created.
Thanks in AdvanceFirst off is that openssl command correct? Should it be this instead:
openssl pkcs8 -inform der -nocrypt -in test.der -out result.pem
Try out your openssl command within a command prompt so that you know that it works ok. I think the command line you specified waits on stdin (well it does for me).
After that.....
runtime.exec creates a Process object. If you do this:
Process openssl = runtime.exec("....")
then you can examine the return code from openssl to see the exit code - for instance if the input file does not exist then exit = 1. You can test for this with Java
Alternatively you could get the stderr from the process and look inside it - if it is 0 length then all is good, if it has some text in there then it has likely failed. You could then throw an exception and include the stderr output in the exception messgae. You may need to experiment with this, runnig it first when openssl is happy then running it again when openssl is upset.
M -
Need to execute tcl script from a Java Program
Hello,
I need to execute a tcl script from a Java Program. But I do not know how to call the tcl Interpreter. Can anybody help me?Iam using the exec command as follows:
Process proc =
rt.exec("C:/SpirentConnect/engines/tcl/8.3.4/windows/s
ctcl.exe C:/Hello.tcl");
But Hello.tcl is not executed.And does that exact string work on the command line?
And what is the return code from running it? -
Sending POSIX signal to an external subprocess from a java program
I'm programing in forte for java under linux-mandrake, I've execute an external subprocess with the runtime and Process clases, I need to send the 2� POSIX signal to this external subprocess, I mean de SIGINT signal, I know that you can send a signal from a shell just doing:
Kill -2 pid // the SIGINT signal is the 2 POSIX signal
I know that there is another system-call like : kill(int signal, int pid) that any one can send from a c program.
Althought I don't know how can I get the pid of a suprocess, because I Know that there is the systemcall in c like:
int getpid() wich gives the pid of the current process, but I need to have the pid of a subprocess not the current one.
The thing is that I do not know how can I do it from a java program, I mean that to send a signal to a subprocess it will work using system-calls, but I do not know if I can insert system call in a java program, I've been thinking about doing it using a linux script like:
#!bin/bash
$a = pidof /home/maude-linux/bin/maude.linux
# this is the path of the process wich is running
kill -2 a$
and the run this script from a java program doing an exec(sh script.bin)
but by the moment I must be doing something wrong in the script because I find mistake in it, it gives me mistake in the assign sentence , I mean:
$a = pidof /home/maude-linux/bin/maude.linux
# this is the path of the process wich is running
I'm not used to program shell scripts, perhaps I'm doing something wrong, is there something wrong in this sentence?.
I would aprecciate some help about this, or if somebody have some idea how to do it in java, I repeat I need to send a signal to a external subprocess wich is launched from a java program by the process and runtime clases, and I need to send a SIGINT signal to the subprocess, I hope that some body can give some suggestion or some code explaining the situationAre the portions of bash-code verbatim in your post?
When yes, they look suspicious!
Instead of
#!bin/bash
#!/bin/bash
would be better.
$a = pidof /home/maude-linux/bin/maude.linux
does not look good either.
If you have command "pidof" telling the pid based on the path name of the executable passed to it as its argument, you can have the output of this program in a shell script like this:
a=$( pidof /home/maude-linux/bin/maude.linux )
Then through $a you will refer to the value of the variable "a":
kill -SIGINT $a
A pidof script could look like this (apart from error handling):
ps -ef|awk '{if (NF>=8 && $8=="'"$1"'") print $2;}'
This works for me; your mileage may vary.
Maybe you are looking for
-
Time Machine Recovery (after data recovery)
Several months ago, Disk2 and Disk3 in my 2007 MacPro 1,1 (OSX 10.7.5) became unreadable by the computer. To make matters worse, the Time Machine external backup became equally as unreadable. All at the same time! Drive 1, with the operating system,
-
"Failed to load database information" error
I know there are many threads on this error, but none appear to apply to my situation. We distribute CR2008 reports with our C#.NET application, connecting to a SQL Server 2005 db . We have had very few problems with our reports, with the exception
-
hi help me for turn on my iphone 4s
-
Show date in dd/mm/yyyy format using ODataModel in a table.
Hi, I am populating a table using ODataMoel in which one of the columns is 'DatePicker' control and I want to map a date being passed in one of the fields of data from server to this DatePicker control. It's getting mapped but I want to show the date
-
Customer statements for credit balances (F.27)
We need to be able to run "Periodic Account Statements in SAP, transaction F.27, for customers that have a credit balance. For clarity, this is a balance that is less than ZERO, for example if a customer has an outstanding credit item on their accoun