View Poll Results: displaying some numbers instead of string/char?

Voters
0. You may not vote on this poll
  • mistake in code?

    0 0%
  • not displaying character set properly and should be included in class path?

    0 0%
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2003
    Posts
    3

    Question Unanswered: displaying some number instead of string/char?

    Hello friends,
    I want urgent help regarding this problem. The following code is working fine only problem is that while displaying addresses at (line 46) it shows some big number instead of actual string/char?
    Why it happening? any idea
    Table definition is in comment at top part !
    Eagerly waiting for help
    Thanks
    ---------------------------------------------------------
    /*
    --create an array of 2 strings (50 chars)
    Create type varray_address_type as varray(2) of varchar2(50);

    --create a table with array type
    Create TABLE customers_with_varray(
    id INTEGER PRIMARY KEY,
    first_name VARCHAR2(10),
    last_name VARCHAR2(10),
    addresses varray_address_typ
    );

    --insert sample into customers_with_varray table

    INSERT INTO customers_with_varray VALUES(
    1, 'Steve','Brown',varray_address_typ('2 State Street, Beantown MA, 12345',4, Hill Street, Lost Town, CA, 54321')
    );

    INSERT INTO customers_with_varray VALUES(
    2,'John',' Doe',varray_address_typ('1 School St, Normal, IL, 61790')
    );

    --see the data entered
    SELECT * from customers_with_varray;
    */


    /*
    CollectionExample1.java shows how to access varrays
    using using weakly typed ARRAY objects
    */

    // import the required packages
    import java.sql.*;
    import oracle.sql.ARRAY;

    import oracle.jdbc.OracleResultSet;

    public class CollectionExampleQuery {

    public static void displayCustomers(Connection myConnection, Statement myStatement) throws SQLException {

    System.out.println("Customers from customers_with_varray:");

    // step 1: create a result set and use it to select
    // the rows from customers_with_varray
    ResultSet customerResultSet = myStatement.executeQuery(
    "SELECT id, first_name, last_name, addresses " +
    "FROM customers_with_varray"
    );

    // step 2: while there are rows in the result set ...
    while (customerResultSet.next()) {

    System.out.println("id = " +
    customerResultSet.getInt("id"));
    System.out.println("first_name = " +
    customerResultSet.getString("first_name"));
    System.out.println("last_name = " +
    customerResultSet.getString("last_name"));

    // a: retrieve the collection from the result set into an
    // ARRAY using the getARRAY() method
    ARRAY addressARRAY =
    ((OracleResultSet) customerResultSet).getARRAY("addresses");

    // b: retrieve the element values from the ARRAY using the
    // getArray() method, storing the element values in an Object array
    String [] addresses = (String []) addressARRAY.getArray();

    // c: read the element values from the Object array
    int radix = 16;
    for (int count = 0; count < addresses.length; count++) {
    // String out_value = (String) addresses[count];
    //System.out.println("addresses[" + count + "] = " + out_value.toString());
    System.out.println("addresses[" + count + "] = " + addresses[count]);
    }
    String s = addresses[0].charAt(2)+""+addresses[0].charAt(3);
    int digit = Integer.parseInt(s);
    System.out.println("s = "+s+";"+Character.forDigit(digit, radix));

    } // end of while loop

    // step 3: close the result set
    customerResultSet.close();

    } // end of displayCustomers()


    public static void main(String args []) throws SQLException {

    // register the Oracle JDBC drivers
    DriverManager.registerDriver(new oracle.jdbc.OracleDriver());

    // create a Connection object, and connect to the database
    // as collection_user using the Oracle JDBC Thin driver
    Connection myConnection = DriverManager.getConnection(
    "jdbcracle:thin:@138.87.169.77:1521ra478",
    "XD478125",
    "pentium3"
    );

    // disable auto-commit mode
    myConnection.setAutoCommit(false);

    // create a Statement object
    Statement myStatement = myConnection.createStatement();

    // display the customers in the customers_with_varray table
    displayCustomers(myConnection, myStatement);

    // rollback the changes made to the database
    // none here; but we had any updates done, this would roll the changes back.
    myConnection.rollback();

    // close the Statement and Connection objects
    myStatement.close();
    myConnection.close();

    } // end of main()

    }

  2. #2
    Join Date
    Jan 2003
    Posts
    3

    those smileys ...

    it is
    jdbcracle:thin:@128.47.179.71:1521:myoracle",

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •