You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by Arunkumar Pillai <ar...@gmail.com> on 2015/11/25 05:59:09 UTC

Need Help in retrieving columns having NULL Values

Hi

I'm using select query to fetch records and my code is as follows

 val connection = DB.getConnection()
    val dataContext:DataContext =
DataContextFactory.createJdbcDataContext(connection)
     var query:Query =
dataContext.query().from("TABLE_NAME").select("COLUMN1").select("COLUMN2").toQuery


      val ds:DataSet= dataContext.executeQuery(query)

      while (ds.next()) {
        val row:Row= ds.getRow()
        val column1= row.getValue(0).toString
        val column2= row.getValue(0).toString

      }



if any of the value is NULL then it breaks there.  Any suggestions or help
would be highly appreciated.

Re: Need Help in retrieving columns having NULL Values

Posted by Arunkumar Pillai <ar...@gmail.com>.
Thanks for the helping in fixing the issue

On Wed, Nov 25, 2015 at 1:18 PM, Tomasz Guziałek <to...@guzialek.info>
wrote:

> Hello Arunkumar,
>
> You cannot call toString method on a NULL value, you can only do it when
> there is a real object assigned to the variable (unless Scala or whatever
> language you are using has some special treatment for such situation). Try:
>
> while (ds.next()) {
>         val row:Row= ds.getRow()
>         val column1= row.getValue(0)
>         val column2= row.getValue(1)
>        if (column1 != null) {
>             val column1StrVal = column1.toString
>        }
>        if (column2 != null) {
>             val column2StrVal = column2.toString
>        }
> }
>
> BTW I also fixed indexes in the getValue calls - there were two times 0. I
> hope that helps!
>
> Pozdrawiam / Regards / Med venlig hilsen
> Tomasz Guziałek
>
> 2015-11-25 5:59 GMT+01:00 Arunkumar Pillai <ar...@gmail.com>:
>
> > Hi
> >
> > I'm using select query to fetch records and my code is as follows
> >
> >  val connection = DB.getConnection()
> >     val dataContext:DataContext =
> > DataContextFactory.createJdbcDataContext(connection)
> >      var query:Query =
> >
> >
> dataContext.query().from("TABLE_NAME").select("COLUMN1").select("COLUMN2").toQuery
> >
> >
> >       val ds:DataSet= dataContext.executeQuery(query)
> >
> >       while (ds.next()) {
> >         val row:Row= ds.getRow()
> >         val column1= row.getValue(0).toString
> >         val column2= row.getValue(0).toString
> >
> >       }
> >
> >
> >
> > if any of the value is NULL then it breaks there.  Any suggestions or
> help
> > would be highly appreciated.
> >
>



-- 
Thanks and Regards
        Arun

Re: Need Help in retrieving columns having NULL Values

Posted by Tomasz Guziałek <to...@guzialek.info>.
Hello Arunkumar,

You cannot call toString method on a NULL value, you can only do it when
there is a real object assigned to the variable (unless Scala or whatever
language you are using has some special treatment for such situation). Try:

while (ds.next()) {
        val row:Row= ds.getRow()
        val column1= row.getValue(0)
        val column2= row.getValue(1)
       if (column1 != null) {
            val column1StrVal = column1.toString
       }
       if (column2 != null) {
            val column2StrVal = column2.toString
       }
}

BTW I also fixed indexes in the getValue calls - there were two times 0. I
hope that helps!

Pozdrawiam / Regards / Med venlig hilsen
Tomasz Guziałek

2015-11-25 5:59 GMT+01:00 Arunkumar Pillai <ar...@gmail.com>:

> Hi
>
> I'm using select query to fetch records and my code is as follows
>
>  val connection = DB.getConnection()
>     val dataContext:DataContext =
> DataContextFactory.createJdbcDataContext(connection)
>      var query:Query =
>
> dataContext.query().from("TABLE_NAME").select("COLUMN1").select("COLUMN2").toQuery
>
>
>       val ds:DataSet= dataContext.executeQuery(query)
>
>       while (ds.next()) {
>         val row:Row= ds.getRow()
>         val column1= row.getValue(0).toString
>         val column2= row.getValue(0).toString
>
>       }
>
>
>
> if any of the value is NULL then it breaks there.  Any suggestions or help
> would be highly appreciated.
>