[newbie] Array of Arrays (JRuby raise an exception)

JRuby raise an exception with the following code :

columnFields = fieldsHash.keys
columnHeaders = fieldsHash.values
selectedFields = fieldsHash.join_keys ", "

datas = Array.new
myRows = query.executeQuery("SELECT " + selectedFields + " FROM " + tbl

  • “;”)
    while myRows.next()
    myCols = Array.new
    fieldsHash.keys.each {|fhk| myCols << myRows.getString(fhk) }
    datas << myCols
    end

model = Table::DefaultTableModel.new

printMethods(model)

print datas, “\n”

model.setDataVector(datas, columnHeaders)
$table.setModel(model)

i suspect de line :

datas << myCols flatten the Array “datas” which has to be an Array of
Arrays that’s to say each element of the Array “datas” has to be an
Array itself (being a set of columns from a database)

the equivalent in Java/BeanShell being Vector of Vectors.

i’m sure (print out) all datas are OK but the structure of them.

then the question is to know if the line “datas << myCols” returns an
Array of Array or simply an concataneted Array ???

···


yt

I’m sure now datas is an Array of Arrays (by printing size) the the
error is comin from elsewhere…

···

Yvon Thoraval yvon.thoravalNO-SPAM@free.fr wrote:

then the question is to know if the line “datas << myCols” returns an
Array of Array or simply an concataneted Array ???


yt

[Yvon Thoraval yvon.thoravalNO-SPAM@free.fr, 2004-03-30 10.44 CEST]

JRuby raise an exception with the following code :

You should give more information if you want help: what exception,
which line, etc.

columnFields = fieldsHash.keys
columnHeaders = fieldsHash.values
selectedFields = fieldsHash.join_keys ", "

datas = Array.new
myRows = query.executeQuery("SELECT " + selectedFields + " FROM " + tbl

  • “;”)
    while myRows.next()
    myCols = Array.new
    fieldsHash.keys.each {|fhk| myCols << myRows.getString(fhk)}

If fieldsHash is a normal ruby Hash, the order of the keys is
arbitrary.

[…]

i suspect de line :

datas << myCols flatten the Array “datas” which has to be an Array of
Arrays that’s to say each element of the Array “datas” has to be an
Array itself (being a set of columns from a database)

the equivalent in Java/BeanShell being Vector of Vectors.

i’m sure (print out) all datas are OK but the structure of them.

then the question is to know if the line “datas << myCols” returns an
Array of Array or simply an concataneted Array ???

To see what is in a variable, use ‘p’ or #inspect. ‘p’ prints,
#inspect returns a string.

$ ruby -e ‘a=[“1”,2,[“3”]]; p a; puts a.inspect’
[“1”, 2, [“3”]]
[“1”, 2, [“3”]]

Good luck.

If fieldsHash is a normal ruby Hash, the order of the keys is
arbitrary.

no, it is a so called “OrderedHash”…

To see what is in a variable, use ‘p’ or #inspect. ‘p’ prints,
#inspect returns a string.

$ ruby -e ‘a=[“1”,2,[“3”]]; p a; puts a.inspect’
[“1”, 2, [“3”]]
[“1”, 2, [“3”]]

ok, tanxs, this will help me a lot seeing the structure of an array
instead of the flatten way used by print…

by the way, i’ve found my error, i had to use JavaUtil::Vector instead
of Ruby Arrays (i’m using JRuby to set a java-swing table model…)

···

Carlos angus@quovadis.com.ar wrote:

yt