Will substr + not function ignore null values ?

hi guys
i have a table test with 1 column named (value) of varchar2 type.
inside this table, i have 3 rows.
1) 2255
2) null
3) 5522
when i do select * from test where substr(value,1,1) not in ('3'), it only returns me
row 1) 2255
row 3) 5522
but why doesnt it return me row 2 with null value as well ?
since substr(null) will generate null. and null is also NOT IN ('3'), why doesnt it shows?
any ideas guys ?

Because NULL is unknown.
By definition you cannot say if unknown is IN or NOT IN anything.
So you have to account for the unknown however you think appropriate, in your case that would mean saying:
select * from test where substr(value,1,1) not in ('3') OR value IS NULL;
[pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Index (or not) for excluding NULL values in a query

    Hello,
    I have table that can become very large. The table has a varchar2 column (let's call it TEXT) that can contain NULL values. I want to process only the records that have a value (NOT NULL). Also, the table is continuously expanded with newly inserted records. The inserts should suffer as little performance loss as possible.
    My question: should I use an index on the column and if so, what kind of index?
    I have done a little test with a function based index (inspired by this Tom Kyte article: http://tkyte.blogspot.com/2006/01/something-about-nothing.html):
    create index text_isnull_idx on my_table(text,0);
    I notice that if I use the clause WHERE TEXT IS NULL, the index is used. But if I use a clause WHERE TEXT IS NOT NULL (which is the clause I want to use), a full table scan is performed. Is this bad? Can I somehow improve the speed of this selection?
    Thanks in advance,
    Frans

    I build a test case with very simple table with 2 columns and it shows that FTS is better than index access even when above ratio is <= 0.01 (1%):
    DROP TABLE T1;
    CREATE TABLE T1
               C1 VARCHAR2(100)
              ,C2 NUMBER
    INSERT INTO T1 (SELECT TO_CHAR(OBJECT_ID), ROWNUM FROM USER_OBJECTS);
    BEGIN
         FOR I IN 1..100 LOOP
              INSERT INTO T1 (SELECT NULL, ROWNUM FROM USER_OBJECTS);
         END LOOP;
    END;
    CREATE INDEX T1_IDX ON T1(C1);
    ANALYZE TABLE T1 COMPUTE STATISTICS
         FOR TABLE
         FOR ALL INDEXES
         FOR ALL INDEXED COLUMNS
    SET AUTOTRACE TRACEONLY
    SELECT
              C1, C2
         FROM T1 WHERE C1 IS NOT NULL;
    3864 rows selected.
    real: 1344
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=59 Card=3864 Bytes=30912)
       1    0   TABLE ACCESS (FULL) OF 'T1' (Cost=59 Card=3864 Bytes=30912)
    Statistics
              0  recursive calls
              0  db block gets
           2527 consistent gets
           3864 rows processed
    BUT
    SELECT
         --+ FIRST_ROWS
              C1, C2
         FROM T1 WHERE C1 IS NOT NULL;
    3864 rows selected.
    real: 1296
    Execution Plan
       0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=35 Card=3864 Bytes=30912)
       1    0   TABLE ACCESS (BY INDEX ROWID) OF 'T1' (Cost=35 Card=3864 Bytes=30912)
       2    1     INDEX (FULL SCAN) OF 'T1_IDX' (NON-UNIQUE) (Cost=11 Card=3864)
    Statistics
              0  recursive calls
              0  db block gets
           5052 consistent gets
           3864 rows processed
    and just for comparison:
    SELECT * FROM T1 WHERE C1 IS NULL;
    386501 rows selected.
    real: 117878
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=59 Card=386501 Bytes=3092008)
       1    0   TABLE ACCESS (FULL) OF 'T1' (Cost=59 Card=386501 Bytes=3092008)
    Statistics
              0  recursive calls
              0  db block gets
         193850 consistent gets
         386501 rows processedHence you have to benchmark you queries with and w/o index[es]

  • ViewRowImpl.writeXML: not to omit null values

    Hi.
    I want to use writeXML method in ViewRowImpl to get current row's data in XML format. Here is a snippet of my code
            Node rootNode = myViewRowImpl.writeXML(1, XMLInterface.XML_OPT_ALL_ROWS);
            StringWriter sw = new StringWriter();
            try {
                Transformer t = TransformerFactory.newInstance().newTransformer();
                t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                t.setOutputProperty(OutputKeys.INDENT, "yes");
                t.transform(new DOMSource(rootNode), new StreamResult(sw));
            } catch (TransformerException te) {
                System.out.println("Transformer Exception");
            System.out.println(sw.toString());
    ...The problem is that there are missing tags of attributes which has null value (does not have a value). How to "force" writeXML method or even transformer to output empty tags for attributes that does not have values definied?
    Thx
    Regards

    As per the doc.
    38.7.3.2 Controlling Element Suppression for Null-Valued Attributes
    By default, if a view row attribute is null, then its corresponding element is omitted from the generated XML. Select the attribute on the Attributes page of the overview editor and in the Property Inspector, select the Custom Properties navigation tab and set the custom attribute-level property named Xml Explicit Null to any value (e.g. "true" or "yes") to cause an element to be included for the attribute if its value is null. For example, if an attribute named AssignedDate has this property set, then a row containing a null assigned date will contain a corresponding AssignedDate null="true"/ element. If you want this behavior for all attributes of a view object, you can define the Xml Explicit Null custom property at the view object level as a shortcut for defining it on each attribute.

  • Ago Function gives NULL values

    Friends,
    I need help regarding Ago function available at column level in BMM.
    I am not at all receiving any error. Unfortunately after Ago function implementation i am getting NULL values for that particular column.
    Here are my implementation steps for getting "Month Ago" values for "Amout column" in Sales table.
    1. i have created Time dimension hieararchy.
    It is like this - Year - > Quarter - > Month - > Actual Date
    2. Defining Keys and making them chronological are also done.
    3. Actual Date is the PK and joins with my Fact.
    4. "Amount" Column in Fact is set to 'Sum'.
    5. i created a new column named " Amount Month Ago" and set following logic to its expression builder.
    Ago("AR Reserve"."Fact - AR Reserve Calc Dtl"."Amount" ,  "AR Reserve"."Dim - TimeDim"."Month" , 1)
    I have not received any error.
    Once i pull this new column (Amont Month Ago) into the presentation layer and try to create a Tabular report. It is not showing any value. Other column values are OK as expected.
    I know i am missing something important here.
    Requesting you all to guide me. I am working on OBIEE 10g.

    Hi,
    Hitting a 'NULL' value in the report hints me of some issues with the Hierarchy/Content setup of the LTS. I suggest you to enable level 7 log and see if the AGO(<measure>) is being nullified by the BI Server due to incompatible facts.
    If it is, then you got to revisit your Period hierarchy and content settings in the Fact LTS. Some generic suggestions are,
    1. Create hierarchies for all dimensions available.
    2. Set the granularity of the sources in the fact to all available hierarchies.
    Hope this helps.
    Thank you,
    Dhar

  • Join is not working  for NULL values on join condition

    HI ,
    I have the following problem .
    SQL> select *from a;
    X Y
    1
    2
    3
    4
    SQL> select *from b;
    B Y
    1
    2
    SQL> select f.x,f.y,s.b from a f,b s
    2 where f.x=s.b(+);
    X Y B
    1 1
    2 2
    4
    3
    SQL> select f.x,f.y,s.b from a f,b s
    2 where f.x=s.b(+)
    3 and f.y=s.y;
    no rows selected
    So now if i include one more join condition where in null = null situation arises , it is now working.
    Simply saying its not treating ( 1 and null ) and ( 1 and null ) are same.
    What is the solution.Is this a expected behaviour.
    Thanks
    Pramod Garre

    HI
    I want something like this
    SQL> select f.x,f.y,s.b from a f,b s
    2 where f.x=s.b(+);
    X Y B
    1 1
    2 2
    4
    3
    SQL> select f.x,f.y,s.b from a f,b s
    2 where f.x=s.b(+)
    3 and f.y=s.y;
    Instead of "now Rows " i have to get
    X Y B
    1 1
    2 2
    4
    3
    Is there is any way to do this.
    Thanks
    Pramod

  • Trigger not changing a null value to -1 on insert, but works on update?

    Here is the trigger I am working on.
    If i update a row it will update the org_type_id to -1. However, nightly a job runs to append new data to the table. I can't change the fact that every day a few "deleted org"'s have a org_type_id as null.
    So, this trigger was supposed to solve it, but it ONLY works if a row is updated, it doesn't work on inserted new rows.
    Thoughts?
    CREATE OR REPLACE TRIGGER MDMR.MDM_ORG_TYPE_ID
    BEFORE INSERT OR UPDATE
    ON MDMR.MDM_ORG
    FOR EACH ROW
    declare
    begin
    if (UPDATING) then
    if ((:old.org_name = 'Deleted Org') and (nvl(:old.org_type_id,0) = 0)) then
    :new.org_type_id := -1;
    end if;
    end if;
    if (INSERTING) then
    DBMS_OUTPUT.put_line ('INSERTING1');
    if ((:new.org_name = 'Deleted Org') and (nvl(:new.org_type_id,0) = 0)) then
    DBMS_OUTPUT.put_line ('INSERTING2');
    :new.org_type_id := -1;
    end if;
    end if;
    end;
    /

    Hi,
    It looks fine to me (or, rather, it would look fine if it were formatted), but I can't test it without your table.
    Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data. In the case of DML problems (like this), the results are the contents of the changed table after each DML operation.
    Are you sure that 'Deleted Org' is spelled exactly the same in the trigger and in your INSERT statements? That includes capital letters and trailing spaces, including those automatically supplied for CHAR columns.
    Does it work when you test it, but fail during the nightly job?

  • String.substring not functioning??

    Hi everyone,
    I am a newbie to Java but couldn't wait to dig in. I am using TEXpad and got the following output. I have also used SunOne and it gave me the same results. Any Ideas?
    This is a snipet of the code I have trouble with. inputLne is a String.
    inputLine = loginRead.readLine();//input from socket stream
    System.out.println(inputLine); //000&000&~ stored in inputLine
    System.out.println(inputLine.length()); // 9 is printed
    System.out.println(inputLine.substring(2,1)); // Exception happens here
    System.out.println(inputLine.substring(2,2));
    System.out.println(inputLine.substring(2,3));
    tempLine = inputLine.substring(2,1);
    The output below is from the code above.
    000&000&~
    9
    Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
    ex out of range: -1
    Thanks in advance for any help.

    Alright, thanks for the advice but I still have a small question.
    The exception is now gone.
    If I use (2,4) I get "0&"
    If I use (2,3) I get the exception error posted above.
    How can I get a substring of one character long? I just want the third "0" from the left "000&000&~".
    Again, thanks for the help.

  • Not to display the null values from data base

    Hiiii.
    In a jsp file i have ten check boxes.The jsp file is mapped to a servlet file for parameter requesting and to
    store it in DB.
    The unchecked box values has null values.All the values are store in a Mysql DB table.
    Again i have to display it in a jsp page from table.
    The problem am facing was,how can i display only the values in a row.it must not display the null values and the crresponding column name.
    Or any other way is their like below
    How i can retrieve only the selected check boxes from tht jsp file.and store in backend.
    Thanks in Advance
    regards,
    satheesh kannan

    Here is a rough example that may give you some ideas:
    On the JSP page:
    <%if(myData.getFirstName()!=null){%>
    Your First Name'
    <input type="text" name="firstName" value="<%=myData.getFirstName()%>">
    <%}%>
    In the servlet:
    String firstName= request.getParameter("firstName");
    if(firstName!=null){
    //write it to the database
    }

  • Alternative for Hashtable that allows null values?

    Hashtable is nice (and reasonably fast) to store key-value pairs. However, if key and value is null, the put() methods throws a NullPointerException. Is there an equivalent type that allows/ignores null values?

    Hi Martin,
    HashMap should do:
    Hash table based implementation of the Map interface. This implementation provides all of the optional map operations, and permits null values and the null key. (The HashMap class is roughly equivalent to Hashtable, except that it is unsynchronized and permits nulls.) This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.
    http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

  • Null Values from a Data Source

    This is more of an implementation question than a
    troubleshooting question. Also, since I've been unable to find any
    documentation on this I was wondering if anyone has come across
    this behavior or found a bug with it.
    Yesterday I was working on an application to explore some
    proof of concept aspects of Flex for an application I'm developing.
    I started running into a problem with Flex Data Services throwing
    back an 'Unknown Property: "clientaddress1"' error whenever I tried
    to update data. It seemed that whenever I tried to update a record
    in the database it would thrown the Unknown Property error. I spent
    a good chunk of the day trying to figure out what was causing this
    and finally gave up and called it a day.
    This morning I was reassessing what the problem was and
    trying to find the differences between my database and my code and
    I stumbled upon the fact that I could add no records and modify
    them without a problem, however if I tried to access an existing
    record and update it I'd get the Unknown Property error.
    I start analyzing the database and found that I'd configured
    the database to use null values for empty values and the records
    that I created with the database had null values, however, any of
    the values inserted from Flex were inserted as blank values. As
    matching my action script class as clientaddress1 = ""; So, upon
    further testing I fould that Flex was not processing the null
    values correctly, so that when it came back and rightly generated a
    Conflict Error...and then called AcceptServer() it was unable to
    find the clientaddress1 property of the class.
    Also, if any of the properties in the database are null it
    throws the same error. Basically it seems to have invalidated the
    object just because one value was null. So if all of my values from
    the DB are set to something and only one field is set to null it's
    still throwing the error on the first alphabetical item of the
    properties.
    I can resolve the problem by not using null values in the
    database, but...what sort of effect would this have on someone
    working with a large legacy database that extensively uses nulls
    for undefined values?
    Also, if a Flex guru could explain the reasoning for this
    happening I would greatly appreciate it!
    Best regards,
    Chris Maloney

    I realize that I didn't clarify that I am using ColdFusion
    for getting the data. This class was generated by the Create CFC
    wizard in Flex Builder.
    package com.generated
    [Managed]
    [RemoteClass(alias="components.generated.clients.Clients")]
    public class Clients
    public var clientid:Number = 0;
    public var clientfirstname:String = "";
    public var clientlastname:String = "";
    public var clientaddress1:String = "";
    public var clientaddress2:String = "";
    public var clientcity:String = "";
    public var clientstate:String = "";
    public var clientzip:String = "";
    public var clientphone:String = "";
    public var clientemail:String = "";
    public function Clients()
    }

  • Removing null values from a chart

    Hello,
    I have a chart embedded in  a Crystal report. (v.11.5).  The data set essentially is a value per date, but because of the way the stored procedure is written, I have null values returned.   Is there anyway to have the chart ignore null values?
    Thanks
    Ray

    Even if the SP returns null values, in your record selection criteria couldnt you just say NOT ISNULL() and thus eliminate null values?

  • How to update the null values to some number on the NUMBER type of column

    Hello All,
    I have one NUMBER type of column in DB table. It has some (null) values. I want to update with value 1. I tried to run the Update statement , It gives 0 rows updated.
    SELECT objectid,attr20 FROM table;
    object id attr20
    ====== ====
    fff70b67-8d54-4ad7-bc57-7b40a0d8b219     (null)
    cac5264a-b363-487b-bfe6-6b84d60064e9     (null)
    2fc2a626-51d8-401c-9495-18aacd4c35c8     (null)
    1b60bfa4-ff68-4488-adf6-2a83528c0e20     (null)
    1c662829-24c1-4b3c-9289-0128e170c043     5
    74f11331-545b-435f-bf4b-f57c7a6b4500     2
    c941c1ac-a18e-47ec-843c-dbe2a5b51001     0
    d7eba203-93c0-48ea-a109-9b06015ef387     0
    eba72fa3-21d8-4489-bb93-917ebbd67de2     0
    I ran following query but no success.
    UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = NULL
    0 rows updated
    UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = null
    0 rows updated
    UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 = ''
    0 rows updated
    UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 =' '
    Error starting at line 1 in command:
    UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 =' '
    Error report:
    SQL Error: ORA-01722: invalid number
    01722. 00000 - "invalid number"
    *Cause:   
    *Action:
    can some one help me out to update such values ????

    Hi,
    "=" will not work for NULL values. Please remeber two NULL values are NOT same. Try IS operator.
    UPDATE eb_tcsservfnadoc SET attr20 = 1 WHERE attr20 IS NULLRegards,
    Avinash

  • How to set a cell to accept null values.

    Hello;
    I am having a problem with my insert query. My form, is passing the year (2010 and up) as a null value. I am using access (ugg) and I can't get it to accept this null value. I have tried setting required to no, and allow zero lenght, even deleted the table and remade it.. STILL I get this error:
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver]Numeric value out of range (null)
    The error occurred in C:\Websites\187914kg3\accManage\signUp.cfm: line 234
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 206
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 204
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 4
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 1
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 234
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 206
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 204
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 4
    Called from C:\Websites\187914kg3\accManage\signUp.cfm: line 1
    232 :         <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#form.securitCode#">,
    233 :         <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#form.ExpirationMonth#">,
    234 :         <cfqueryparam value="#FORM.ExpirationYear#" cfsqltype="CF_SQL_VARCHAR">)
    235 : </cfquery>
    236 :
    SQLSTATE
      22003
    SQL
       INSERT INTO MerchandiseOrdersItems (c_ID, cc_type, cc_num, cc_verify, cc_expir_m, cc_expir_y) VALUES ( (param 1) , (param 2) , (param 3) , (param 4) , (param 5) , (param 6) )
    VENDORERRORCODE
      3
    This is my form element and query that is causing the problem:
    <cfparam name="FORM.ExpirationYear" default="">
    <form>
    <select name="ExpirationYear" class="formSelect">
               <cfloop index="i" from="#VARIABLES.y1#" to="#VARIABLES.y2#">
                  <option value="#i#"<cfif FORM.ExpirationYear EQ i> selected</cfif>>#NumberFormat(i,"0000")#</option>
               </cfloop>
             </select>
    </form>
    <cfquery datasource="#APPLICATION.dataSource#" dbtype="ODBC">
    INSERT INTO MerchandiseOrdersItems
    (c_ID, cc_type, cc_num, cc_verify, cc_expir_m, cc_expir_y)
    VALUES (<cfqueryparam value="#getUpdate.NewID#" cfsqltype="CF_SQL_VARCHAR">,
            <cfqueryparam cfsqltype="cf_sql_varchar" value="#form.creditType#">,
            <cfqueryparam cfsqltype="CF_SQL_LONGVARCHAR" value="#form.creditCard#">,
            <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#form.securitCode#">,
            <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#form.ExpirationMonth#">,
            <cfqueryparam value="#FORM.ExpirationYear#" cfsqltype="CF_SQL_VARCHAR" null="yes">)
    </cfquery>
    The string that is erroring is this:
    <cfqueryparam value="#FORM.ExpirationYear#" cfsqltype="CF_SQL_VARCHAR">
    I still get this error. SO It has to be something inside the access database not allowing this null value. It is set as text right now, allowing zero length and not required.
    Can anyone help me please?

    Hi
    Usually the error occurs due to mismatch in datatype of db field and cfsqltype of cfqueryparam. Is "FORM.ExpirationYear " of type date?.
    If so <cfqueryparam value="#FORM.ExpirationYear#" cfsqltype="CF_SQL_DATE" null="yes">)
    "http://www.adobe.com/livedocs/coldfusion/6.1/htmldocs/tags-b20.htm" (have a look ).
    Hope this will solve your issue

  • How can I avoid the null values in cross tab?

    How can I avoid the null values in cross tab?

    Hello Anindita,
    Let me explain you the problem in detail.
    I have selected User and Program as rows in the cross tab. In Summarized Field I am counting the Programs.
    In DB I can have both User and Program null.
    Letu2019s take these scenarios...
    1) For a User, Program can be null
    2) For a Program, User can be null
    3) And both can be null.
    A null Program does not give problem since Cross tab does not count the null values and in my case too, it remove the Program which are null from the Cross tab because of the counting its doing on Program. Hence scenario 1 and 3 is not a Problem.
    Problem comes in scenario 2 (For a Program, User can be null).
    In this case since Program is not null it will get counted and will be grouped under null user but I donu2019t want to show the null user Grouping in my cross tab.
    "Suppress empty rows" and "suppress empty colums" does not help.
    Thanks & Regards,
    Amrita

  • Need help Take out the null values from the ResultSet and Create a XML file

    hi,
    I wrote something which connects to Database and gets the ResultSet. From that ResultSet I am creating
    a XML file. IN my program these are the main two classes Frame1 and ResultSetToXML. ResultSetToXML which
    takes ResultSet & Boolean value in its constructor. I am passing the ResultSet and Boolean value
    from Frame1 class. I am passing the boolean value to get the null values from the ResultSet and then add those
    null values to XML File. When i run the program it works alright and adds the null and not null values to
    the file. But when i pass the boolean value to take out the null values it would not take it out and adds
    the null and not null values.
    Please look at the code i am posing. I am showing step by step where its not adding the null values.
    Any help is always appreciated.
    Thanks in advance.
    ============================================================================
    Frame1 Class
    ============
    public class Frame1 extends JFrame{
    private JPanel contentPane;
    private XQuery xQuery1 = new XQuery();
    private XYLayout xYLayout1 = new XYLayout();
    public Document doc;
    private JButton jButton2 = new JButton();
    private Connection con;
    private Statement stmt;
    private ResultSetToXML rstx;
    //Construct the frame
    public Frame1() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    //Component initialization
    private void jbInit() throws Exception {
    //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]")));
    contentPane = (JPanel) this.getContentPane();
    xQuery1.setSql("");
    xQuery1.setUrl("jdbc:odbc:SCANODBC");
    xQuery1.setUserName("SYSDBA");
    xQuery1.setPassword("masterkey");
    xQuery1.setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
    contentPane.setLayout(xYLayout1);
    this.setSize(new Dimension(400, 300));
    this.setTitle("Frame Title");
    xQuery1.setSql("Select * from Pinfo where pid=2 or pid=4");
    jButton2.setText("Get XML from DB");
    try {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    catch(java.lang.ClassNotFoundException ex) {
    System.err.print("ClassNotFoundException: ");
    System.err.println(ex.getMessage());
    try {
    con = DriverManager.getConnection("jdbc:odbc:SCANODBC","SYSDBA", "masterkey");
    stmt = con.createStatement();
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    jButton2.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jButton2_actionPerformed(e);
    contentPane.add(jButton2, new XYConstraints(126, 113, -1, -1));
    //Overridden so we can exit when window is closed
    protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
    System.exit(0);
    void jButton2_actionPerformed(ActionEvent e) {
    try{
    OutputStream out;
    XMLOutputter outputter;
    Element root;
    org.jdom.Document doc;
    root = new Element("PINFO");
    String query = "SELECT * FROM PINFO WHERE PID=2 OR PID=4";
    ResultSet rs = stmt.executeQuery(query);
    /*===========This is where i am passing the ResultSet and boolean=======
    ===========value to either add the null or not null values in the file======*/
    rstx = new ResultSetToXML(rs,true);
    } //end of try
    catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    ======================================================================================
    ResultSetToXML class
    ====================
    public class ResultSetToXML {
    private OutputStream out;
    private Element root;
    private XMLOutputter outputter;
    private Document doc;
    // Constructor
    public ResultSetToXML(ResultSet rs, boolean checkifnull){
    try{
    String tagname="";
    String tagvalue="";
    root = new Element("pinfo");
    while (rs.next()){
    Element users = new Element("Record");
    for(int i=1;i<=rs.getMetaData().getColumnCount(); ++i){
    tagname= rs.getMetaData().getColumnName(i);
    tagvalue=rs.getString(i);
    System.out.println(tagname);
    System.out.println(tagvalue);
    /*============if the boolean value is false it adds the null and not
    null value to the file =====================*/
    /*============else it checks if the value is null or the length is
    less than 0 and does the else clause in the if(checkifnull)===*/
    if(checkifnull){ 
    if((tagvalue == null) || tagvalue.length() < 0 ){
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    else{
    users.addContent((new Element(tagname).setText(tagvalue)));
    root.addContent(users);
    out=new FileOutputStream("c:/XMLFile.xml");
    doc = new Document(root);
    outputter = new XMLOutputter();
    outputter.output(doc,out);
    catch(IOException ioe){
    System.out.println(ioe);
    catch(SQLException sqle){

    Can someone please help me with this problem
    Thanks.

Maybe you are looking for