Variant class and ADO.Recordset.getRows()

Hello All,

I'm a newbie to Java/J++ and I'm writing a data access wrapper to
encapsulate ADO functionality.  I have a function
that takes a SQL statement and returns a two dimenisional variant array
representing the SQL resultset.  I am trying to
use the ADO.Recordset.getRows() function and it seems to work.

The problem is, how the heck to I get the information out of the Variant
object I have created?  In VB I just used the
variant array like such:  target =  vArray(2,1) but I can't figure out how
to do this in J++.

Here is what my code looks like...

import com.ms.com.*;

file://Private member variables
 private Variant mvRecords = null;

public Variant getVariantArrayFromSQL(String sSQL)
  {
   Recordset rst = new Recordset();
   Connection con = new Connection();

   con.setConnectionString(msConnectString);
   con.open();

   rst.setActiveConnection(con);
   rst.setCursorLocation(AdoEnums.CursorLocation.CLIENT);
   rst.setCursorType(AdoEnums.CursorType.KEYSET);
   rst.open(sSQL);

   mvRecords = rst.getRows();
   return mvRecords;
  }

...again, this function seems to work (I get no errors and the array seems
to be returned correctly to the calling client) but I can't figure out how
to use
the mvRecords object to get the data out of it!!!   There are a bunch of
methods like .getBoolean and .getInteger but they're not working for me and
I can't
find anything in the help or on MSDN that shows me how to use this object.

Any help would be much appreciated.

Thanks,

Craig


ckosterAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JodCommented:
getRows will return you a two dimensional array of objects.

mvRecords = rst.getRows();

where mvRecords is a Variant. You now have to use:

SafeArray sa = mvRecords.toSafeArray();
               
to get the data into a useable form.

Now with sa you can use:

sa.getString(1, 1)

to get field 1 in row 1 of your recordset as a string. SafeArray's are used by Microsoft for transporting data between different languages (such as Visual C++ to Visual Basic).


To quote the docs...

"Use the GetRows method to copy records from a Recordset into a two-dimensional array. The first subscript identifies the field and the second identifies the record number. The array variable is automatically dimensioned to the correct size when the GetRows method returns the data."


An Example is here but it is very badly written and very messy but it does you how to access the data:

http://msdn.microsoft.com/library/psdk/dasdk/mdae7wfe.htm


I'm so glad I don't have to use J++ - it doesn't even look like Java anymore by the time Microsoft have finished with it. It's more like they have grafted Java onto VB.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ckosterAuthor Commented:
Thanks, Jod.  I dumped the resultset to the safearray and everything worked great.

Re:  your comments about J++...I am just learning java and I'm using J++ as the tool to learn and it does make me a little concerned about the "purity" of the java language.  I know you can disable the Microsoft Java Extensions in the J++ IDE.  Would you suggest doing this to help me learn the non-MS version of Java?

I also have a copy of Borland's JBuilder sitting around.  Do you think that would be a better learning tool for me to get a grasp of what "real" Java is about.

Any advice would be much appreciated.

Thanks,

Craig
0
JodCommented:
I'm not usually one to get worried about this sort of thing - using the right tools for the right job is my motto.

But I have to say that the code above is so different to anything available in standard Java that what you are really learning is not how to program in Java but how to program J++.

This knowledge will be no good to you if you have to access databses using Java's own database drivers, which use the JDBC standard.

JBuilder is quite highly rated and will give you a better feel for how Java really works. Visual Age for Java and Visual Cafe are also very good.

Personally I currently have to use a text editor (Programmers File Editor) and the sun JDK which is unfortunately due to the OS I am working on. No better way to learn though...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.