• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

vector and resultset

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing a Type 3 JDBC Driver where network protocol is RMI.

I am invoking this remote method.
queryInf query = (queryInf)Naming.lookup("rmi://localhost:1099/queryService");

Vector queryResult = query.execute(schema,datasource,select,from);

The result is returned as a vector.

Now in my driver I need to implement the ResultSet interface(specifically next() and getString()) to find whether there is any more element and to get the element.

How can I approach to implement those method on a vector?
Is there anyway to convert a vector to a resultset?
or I have to manipulate the vector only ? If so how to maintain the state of the cursor position in a vector?

please help and let me know if you need any more information..
Thanks in advance...
 
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avijit,
Take a look at Iterator. You can call vector.iterator() to get one. This implements next() for you so you can just delegate to the iterator.

You would still need to implement the rest of the methods on ResultSet though. For the getXXX() ones, you can call getNext() on the Iterator and then convert to the appropriate value.

Just curious - why are you writing your own driver? Most database vendors provide one.
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am writing this Driver for one of my application called Data Mediator.
So in other words you can say it is a application specific driver.
The data mediator application converts the data from various source into a local schema known to user. In fact the user gives query in the local schema even though he/she is not aware of the schema of the foreign database. There are some XML parsing involved in that.
I have used RMI for making the application disttributed. Now I am writing the driver so that by only changing the url one could select and change the schema and datasource.
the url is like
jdbc:mediator:localhost:1099:local:foreign

I hope I answered your question.
Thanks for your help.I will look into iterator. Please let me know if you have any more idea.
Thanks
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why don't u try thru Type 4 driver. Because Type 3 is expensive driver.
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe for Type 4 driver we have to use different driver for different database. The type 4 driver converts the JDBC calls into the vendor specific database management system protocols so that client application can communicate directly with the database server.
But in my application I dont want that. It is a 3 tier application where client connects to the middle tier(mediator application) using RMI as net protocol.
The jdbc calls from the client is passed to the middle tier through RMI. The middle tier then takes care of the rest of the thing (connecting to the back end database, mediating between database etcetera)

Do you see my point ??
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe Jeanne is correct, you just need to implement an adapter (a nice example of this pattern is in Head First Design Patterns, but that's heading off topic)

You just need something like this:


The internal iterator is used to step forward, and the 'current' is used to hold the window on the current item, hopefully it mimc the RS behaviour implemented by an internal iterator. You could always use v.get(i), but I guess it depends on your application.

Dave
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avijit,
That's a good reason for writing a driver. Very interesting!

One thing I would change in Dave's adapter: Pass in a List instead of a Vector. It makes the code more flexible because you can pass in an ArrayList in the future without changing the code.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Design to the interface, good point. My fault for following the instructions implicitly
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Pass in a List instead of a Vector"
I wish I could do that. I wish I could just pass in a resultset.
But the problem is in the mediator application ,I am getting the resultset from the database, storing the values in a vector , then I am doing some other operations on it(translating etc.)
That's why I am passing the vector.
I am working on Dave suggestion(iterator()).Seems like I got a lead now.
I will let you know in case I have any further problem.
Thanks for all the valuable advise.
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ahoy !!! It works....
one small thing....
boolean result = iter.hasNext();
if(result)
{
current = iter.next();
}
return result;

I think we are moving the position of the cursor two position ahead.
(I tried that and I got the all the even records missing..)
What I did is i just returned result ..
Am I right or there is something I am missing...
Thanks
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeannes point (and a good one) was to make this small change to the constructor:


A vector is a List so you can still pass in your Vector as normal.
I don't think the code above will cause it to skip the odd records. Iterator.hasNext() peeks at the next to see if it exists, Iterator.next() moves it forward. As long as you use current to return values in your getters and not iter.next() you should be fine.

[EDIT - formatted the code a bit]
[ March 08, 2005: Message edited by: David O'Meara ]
 
Jeanne Boyarsky
author & internet detective
Posts: 41878
909
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Avijit,
What method is the code you posted from? It may be a semantics issue of something getting called twice.

Dave's code example is exactly what I meant. Since you are only using the iterator() method of Vector, you can pass in any class interface that implements it. In this case, your main choices are Vector, List and Collection. I would avoid Vector because it is too specific. Collection has different (unordered) semantics, so it means something different than what you want. List is right in the middle, so the best choice here.
 
Neel Chow
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David
You are right..I am using next() in my getters instead of the current....thats why i missed some elements..
I made the correction...thanks
reply
    Bookmark Topic Watch Topic
  • New Topic