Results 1 to 12 of 12

Thread: Doubt

  1. #1
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Thumbs down Doubt

    public List getEventKeys() throws SQLException, UnknownHostException {
    PreparedStatement getEventKeys = null;
    ResultSet rs = null;
    try {
    //get the host
    String hostName = InetAddress.getLocalHost().getHostName();
    String sql = "select event_key from event_trigger where" +
    "EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER'" +
    "AND VALUE = ?)";
    List eventKeys = new ArrayList();

    getEventKeys = conn.prepareStatement(sql);
    getEventKeys.setString(1,hostName);
    rs = getEventKeys.executeQuery(sql);
    while (rs.next()) {
    eventKeys.add(rs.getInt("event_key"));
    }

    return eventKeys;
    } finally {

    //close statement and result set
    getEventKeys.close();
    rs.close();

    }


    __________________________________________________ _____________

    Getting a null pointer exception at -rs.close-

    and rs = getEventKeys.executeQuery(sql); does not excecute..

    what could be the prob

  2. #2
    exodus is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    Ideally you would get a null pointer exception there when there is no rs object for Java to close.

    So a simple check would solve the issue.
    Java Code:
    if (rs != null) {
    rs.close();
    }
    You are not having any results in your rs, so you are getting this exception. If the results should be there, then there is something wrong with your query.

    PS: Please name your topics better. Doubt is not a nice name ;)

  3. #3
    exodus is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    Try this

    Java Code:
     
    public List getEventKeys() throws SQLException, UnknownHostException {
     
    PreparedStatement getEKeys = null;
    ResultSet rs = null;
    Connection locCon = null;
    List eventKeys = new ArrayList();
     
    try {
    //get the host
    String hostName = InetAddress.getLocalHost().getHostName();
    String sql = "select event_key from event_trigger where" +
    "EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER'" +
    "AND VALUE = ?)";
     
     
    getEKeys = locCon.prepareStatement(sql);
    getEKeys.setString(1,hostName);
    rs = getEKeys.executeQuery(sql);
     
    while (rs.next()) {
      eventKeys.add(rs.getInt(1));
    }
     
    return eventKeys;
    }
     
    finally {
    if (rs != null) {
    rs.close();
    }
    if (getEKeys != null) {
    getEKeys.close();
    }
    }
    Last edited by exodus; 10-27-2009 at 08:02 PM.

  4. #4
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Default

    do we have to intialize the connection resultset and prepared statement..

    it is showing an error.. and askin to initalize

  5. #5
    exodus is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    yeah i think it is better to do that..

    Java Code:
    PreparedStatement getEKeys = null;
    ResultSet rs = null;
    Connection locCon = null;

  6. #6
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Default

    no dude.. not working..!!

    i guess connection cannot be initailized to null.. so i still point to the global connection established..!!

    but even then, i don not manage to get a result in the result set..

    :mad::mad::mad:

  7. #7
    exodus is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    May be you can just say
    Java Code:
    Connection locCon = new Connection();
    Then we can be sure the global thing is not causing any problem if it still does not work

  8. #8
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Default

    I tried the global connection... and all the rest of the things remain the same..

    i change just the sql to a simple select statement.. and it works fine..!!

    now somethings wrong wit that sql and passing a parameter to the sql.. is that correct??

  9. #9
    exodus is offline Member
    Join Date
    Oct 2009
    Posts
    5
    Rep Power
    0

    Default

    yes, that could be it. nice catch btw...

    when you debug the program in eclipse or netbeans, just before the executeQuery statement is passed, see what is the value stored in the string variable sql..

    copy that value and run it in sql editor or some program and see if you get a result.. this will help you identify if the query is correct or not..

  10. #10
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Default

    the issue is still not resolved..!!

    as i said its something seriosulsy to do witht he sql.. but the sql executes perfectly on the sql editor. whereas on the program it jsut spits out errors..

    the excetion that i got this time on with the actuall sql was..

    ORA-03115: unsupported network datatype or
    representation

    but its got nothin to do with the DB version adn criver version as it seems to be...

    i simply replace the sql again with the simple select stmt.. i am able to get thru..

    but why isnt the original one wrking..??

    :mad::mad::confused::confused::(

  11. #11
    Join Date
    Oct 2009
    Posts
    15
    Rep Power
    0

    Default

    missed the damn \n after the query end of line
    instead of this -->
    String sql = "select event_key from event_trigger where" +
    "EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER'" +
    "AND VALUE = ?)";

    it had to be this -->

    String sql = "select event_key from event_trigger where \n" +
    "EXISTS (SELECT VALUE FROM CONTROL_PARAM WHERE UPPER(KEY) = 'ACTIVESERVER' \n" +
    "AND VALUE = ?)";

    damn..!!:eek::eek:

  12. #12
    iceagecoming is offline Member
    Join Date
    Nov 2009
    Posts
    11
    Rep Power
    0

    Default

    You don't need the '\n' at the end of the lines, but you do need some whitespace. Your SQL would have looked like this:

    "whereEXISTS" and "'ACTIVESERVER'AND"

Similar Threads

  1. have doubt
    By ras_pari in forum Advanced Java
    Replies: 3
    Last Post: 10-01-2009, 10:51 AM
  2. doubt
    By Chris555 in forum Networking
    Replies: 0
    Last Post: 08-05-2009, 03:58 PM
  3. Doubt
    By winkodes in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 12-20-2008, 09:34 PM
  4. doubt
    By shaju_inspira in forum Sun Java Wireless Toolkit
    Replies: 0
    Last Post: 01-18-2008, 09:38 AM
  5. doubt in jms
    By veena in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 01-05-2008, 02:42 PM

Posting Permissions

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