Accessing oracle DB from a java program - question for oracle driver

Hi,
I have Oracle 10 G under vista on my desktop. I am trying to write a simple java program to access/update database tables. I saw in one of oracle example to import 2 packages - namely --- import oracle.jdbc.driver.*; import oracle.sql.*;
Where do I find these 2 packages. Also I read some documentation to download drivers. I would like to use 2 drivers, the thin driver and the OCI driver. Can someone tell me where I can find these drivers and where do I copy these two drivers - so javac and java command can recognize it.
I will greatly appreciate the help. Julia
My program is as follows
(It was working few years ago but things have changed now and I have Vista because my old machine died):
import java.sql.*; // JDBC package
//import com.inet.tds.JDBCRowSet;
import java.util.*;
import oracle.jdbc.driver.*;
import oracle.sql.*;
public class HomeDB
run as follows:
C:\Documents and Settings\MMM>cd \jj
C:\john>set CLASSPATH=.;c:\oracle9i\classes12;%CLASSPATH%
C:\john>javac HomeDB.java
C:\john>java HomeDB
King: 24000.0
Kochhar: 17000.0
De Haan: 17000.0
Hunold: 9000.0
Ernst: 6000.0
Austin: 4800.0
public static void main(String[] argv)throws SQLException
Connection conn=null;
try // may throw a SQLException
conn = getConnection();
doQuery (conn);
catch (SQLException e)
System.err.println(e.getErrorCode() + ": " + e.getMessage());
finally // make sure the connection is closed
if (conn != null) try {conn.close();} catch (SQLException e) {};
//out.close(); // close PrintWriter stream
private static Connection getConnection() throws SQLException
String username = "scott";
String password = "tiger";
String url = "jdbc:oracle:thin:@localhost:1521:newora";
// "jdbc:oracle:thin:@localhost:1521:COCKYJOB";
Connection conn = null;
String driver = "oracle.jdbc.driver.OracleDriver";
try {
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
} catch ( ClassNotFoundException cnfex ) {
System.err.println(
"Failed to load JDBC/ODBC driver." );
cnfex.printStackTrace();
}catch (Exception e){
e.printStackTrace();
//DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
conn = java.sql.DriverManager.getConnection(url,username,password);
conn.setAutoCommit(false);
return conn;
private static void doQuery (Connection c) throws SQLException
// statement to be executed
String query = "SELECT ename, job, mgr FROM EMP";
Statement st = null;
ResultSet rs = null;
try // make sure the close statements are executed (in the finally block)
// create the statement
st = c.createStatement();
// execute the query
rs = st.executeQuery(query);
// process results
while (rs.next())
// get the employee last name
String eName = rs.getString("ename");
String eJob = rs.getString("job");
String eMgr = rs.getString("mgr");
System.out.println("Emp Name:" + eName +
"Job: " + eJob +
"MGR: " + eMgr);
finally // make sure the close statements are executed
// close the result set if it exists
if (rs != null) try {rs.close();} catch (Exception e) {};
// close the statement if it exists
if (st != null) try {st.close();} catch (Exception e) {};
Edited by: user455788 on Dec 19, 2008 9:13 PM

You can download the drivers from http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html.
Note that oracle.jdbc.driver is desupported after 10.2, http://forums.oracle.com/forums/ann.jspa?annID=201, so you might want to consider using a DataSource to provide Connections.
E.G.
{message:id=2819114}

Similar Messages

  • 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 you

    jayanthds, 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"

  • Accessing Sql Server from AS400 Java program

    Hi everybody,
    I am trying to access Sql Server from an AS400 Java program. I have tried various Sql Server JDBC drivers including the Microsoft one but no luck yet. When i try to compile my Java program (with driver file in the classpath) it gives some errors on the driver jar file and also it throws out lots of unreadable text characters. This gave me a feeling that probably its a character coding issue with the jar file, so i tried ftp the file in binary mode as well as copying through the Operations Navigator. But still compilation is giving the same kind of errors.
    Do I need to have some special JDBC Drivers compiled for AS400 specifically. My understanding was that Java is platform independent so any JDBC Type 4 driver will work.
    We are running Java 1.3 on the AS400. Any help on this issue would be great.
    Thanks
    Inder

    Thanks for the help. I am writing a Java program after a long time that's why was making that mistake. Now the program gets compiled correctly but on running the program i am getting the following error message:
    java 001-0070: Exception JVAB544 not expected
    /myjava/test/msbase.jar: 001-0050 Syntax error on Line 1: token ')' not expected
    /myjava/test/msutil.jar: 001-0050 Syntax error on Line 1: token ')' not expected
    /myjava/test/mssqlserver.jar: 001-0050 Syntax error on Line 1: token ')' not expected
    I have no idea what is this error about. Though the same driver files don't give any error when running on a Windows machine.
    Thanks

  • 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 PM

    Assuming 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

  • Execute several UNIX OS commands from inside Java program

    Greetings,
    I would like to be able to execute from a Java program several of the following UNIX commands
    script filename
    cd
    date
    grep
    diff
    I have been able to get a single command to work with
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("dir");
    My goal here is to accomplish a Java program which will use JDBC to access an Oracle database with SQL and then compare the resultant flat file with a diff command in Unix to another delimited file from an Excel spreadsheet. Your input is appreciated.
    Thank you

    I would suggeat to use JDBC to get the data from database and then read your file and then use existing java diff program from following link to find the differences between the files
    http://www.bmsi.com/java/
    I hope this helps
    VAN

  • Executing a stored procedure from a java program

    Hi.. how can i call a oracle stored procedure from a java
    program. the OSP has four IN parameters and one OUT parameter(a
    cursor). when i try this way.. i get an error
    con = DriverManager.getConnection(url, "stored", "stored");
    CallableStatement cs =
    con.prepareCall(
    "{call stored_proce_1(?,?,?,?,?)}");
    cs.registerOutParameter(1, OracleTypes.CURSOR);
    cs.setString(2, "14541");
    cs.setString(3, "gen");
    cs.setInt(4, 0);
    cs.setInt(5, 5);
    ResultSet rs =cs.getResultSet();
    while(rs.next()){
    System.out.println(rs);
    appreciate ur help.
    qs

    I'm no expert on this, but I have a similar call where I fetch
    an Oracle REF CURSOR from a call to a stored function. If you
    fetch the cursor as an Object from your CallableStatement, you
    can then cast it to a ResultSet e.g.
    mystatement.executeUpdate();
    ResultSet rs = (ResultSet) mystatement.getObject(1);
    Then you should be able to loop through your ResultSet as usual.
    Good luck!
    Chris

  • 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);
         }

  • 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 Nikom

    Thank 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 read a variable from a java program?

    Hey guys
    I don't actually have a single clue about java itself. I usually use other languages. But i need to get the value of a variable/label from a java program.
    After googling a bit i installed Java Access Bridge to get some more info how to find that value. Using JavaMonkey i got following accessibility info:
    AccessibleContext information at mouse point [0, 0]:
    Name: Spin:
    Description:
    Role: label
    Role in en_US locale: label
    States: enabled,focusable,visible,showing
    States in en_US locale: enabled,focusable,visible,showing
    Index in parent: 0
    Children count: 0
    Bounding rectangle: [421, 152, 598, 169]
    Top-level window name: WEedit
    Top-level window role: frame
    Parent name:
    Parent role: panel
    Visible descendents count: 0
    This label contains a value that i need. I'd like to write it to a textfile periodically or put it into the clipboard. Shouldn't be more than some lines of code.
    Would appriciate any help.
    Thank you and merry christmas

    Nachtschicht wrote:
    Well, i play google for you: http://java.sun.com/javase/technologies/accessibility/accessbridge/
    So you tell me you can't extract any information out of this?
    AccessibleContext information at mouse point [0, 0]:
    Name: Spin:
    Description:
    Role: label
    Role in en_US locale: label
    States: enabled,focusable,visible,showing
    States in en_US locale: enabled,focusable,visible,showing
    Index in parent: 0
    Children count: 0
    Bounding rectangle: [421, 152, 598, 169]
    Top-level window name: WEedit
    Top-level window role: frame
    Parent name:
    Parent role: panel
    Visible descendents count: 0
    You don't have any hint, how i as a non-java programmer can access data out of a simple java program?No. That's a horrible way to interact with a program. A better way would be if it exposed some API. Or there was a web service you could call, for example.

  • Calling another application from a java program

    Hi, Java ppl.
    I wanted to know how can I call another program say a help application or an exe from a java program. anyone with any advice or a piece of code would help.
    Thanks
    Pradeep

    I had the same situation and I tried the code that you sugested and it works. I was wondering, what am I expecting in the while loop that appears after the int inp; statement? Is some data going to be displayed on the screen? How essential is to have that while loop after the calling the exec() method?
    Sorry for the amount of questions, I never tried this before.
    Best regards,
    Luis E.

  • 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
    Roopali

    hello 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 a Linux command "clear" from a Java program

    Hello. How to run a simple linux command to clear the screen from a Java program. I did the following
    Process p = Runtime.getRuntime().exec("clear");
    Nothing is happening.

    you're not supposed to mess with the shell, youdon't own it and
    shouldn't try to dictate what happens with it.
    The shell is a multiuser system,What?
    The command shell (for example sh, ksh, bash, csh,
    zsh) is a process, a command interpeter just like any
    other (user mode) program.
    yes, and there can be multiple processes writing to it at any one time.
    You do NOT have exclusive access to it, nor should you ever assume you do.
    In a multiuser system there can be several shells
    running on behalf of several users. The same user can
    run several shells.
    Yes, and each shell can be accessed by multiple processes at any one time.
    So what?
    Process a writes to the shell.
    Process b writes to the shell.
    Process a clears the shell, removing whatever process b wrote there.
    You've just messed up process b, or at the very least its output.
    Do NOT assume you have exclusive access to any shell.

  • How to call j2me emulator instance from a java program?

    hi,
    how to call j2me emulator instance from a java program?
    i tried public void startApp(){
    try{
    platformRequest("tel:+5550000");
    }catch(Exception e){
    e.printStackTrace();
    from a j2me midlet itself,
    but it gave illegal access exception.
    do i need any hardware phone connected to my pc?
    please help.

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    import java.util.*;
    public class OpenExplorer{
    public static void main(String args[]){
         new OpenExplorer();
    public OpenExplorer(){
         try{
         String command = "explorer C:";
         // or String command = "cmd /c explorer C:";
         Runtime runtime = Runtime.getRuntime();
         Process process = runtime.exec(command);
         int exitVal = process.waitFor();
         System.out.println("Exit Value: " + exitVal);
         } catch(Exception e){
         e.printStackTrace();
    }

  • 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 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

Maybe you are looking for

  • Cloning 11.1.0.6 and attach in 11.1.0.7

    hi, we have two environments, 11.1.0.6 and 11.1.0.7 in windows 2003 in separate machines we are planning to move 11.1.0.6 databases to 11.1.0.7. is it possible to clone 11.1.0.6 database by using the method, backup control file to trace/cold backup a

  • Can't enable WiFi in iOS 7

    My wife has an iPhone 4s and upgraded to iOS7 yesterday. Today, she's unable to turn on wifi. Even if we go into wifi in the system prefrences, it's like it's diabled. It won't toggle. If I go in via the drawer at the bottom, it allows me to turn on

  • For Mobile purchases

    Hi, I live in India. I want to purchase blackberry Mobile in 2015. Which model is best bb z3 or bb z10?! I am so confused for bb z10 because it is too older phone that appears in Indian market but feature is now better than z3. .. If I purchase bb z1

  • Service error - ECC_EMPTIMSHEETCHGRC - XML Serialization Error

    I am not able to execute the service - EmployeeTimeSheetChangeRequestConfirmation_In (http://<host:port>/sap/bc/srt/xip/sap/ECC_EMPTIMSHEETCHGRC?sap-client=<number>&wsdl=1.1&mode=sap_wsdl) in the discovery system. I am getting the following error - X

  • HI REGORDING BDC

    HI EXPERTS CAN U HELP ME FOR THIS THANKS <b>HOW DOES WE  KNOW THAT THE LEGACY FILES HAVE COME ON TO THE SAPSERVER YOUR WORKING ON? </b>