Ken Matson

Ranch Hand
+ Follow
since Mar 01, 2018
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ken Matson

Hi there  - suppose I have:

is there any way to set up a binding between x and y so that if one changes, the other changes to the same value and vice-versa? This is a major simplification of the actual code/design, but if i could get this specific answer, it would be very helpful.

1 month ago

Campbell Ritchie wrote:

Ken Matson wrote:. . . you ask how to put gas in your lawnmower, and everyone starts telling you you've got the wrong kind of yard, and do you really need a lawnmower, and why is your lawnmower red and not green, etc. etc. etc. . . .

If you cut green grass with a red lawnmower you will end up with short grass. If you program something badly, like elevators on aeroplanes, you can kill 300 people. We see people who really intend to use w=code even worse than yours. That is why we worry about the whole of your code.

You take your car to the garage and ask for a new tyre. They don't notice your brakes hardly work any more. That is why we worry about the whole of your code.

Yes, the whole idea of generics is to avoid casting. Which means if you are casting anything you aren't using generics right.

Well sorry - none of the SAMPLE was the "whole of my code" - only a fragment to illustrate issue. To use your tire example, if i take the tire off the car and take it to the shop to get a flat repaired, I don't expect them to start querying me about the rest of my car, etc. Oh well - agree to disagree.

So on a serious note - and I hear you on the generics/casting BTW - then how do I do this:

suppose A is a superclass and B, C, D, E  are separate subclasses of A
I have another class G which has on it an ArrayList L which Is defined generically so that I can populate it with B,C,D,E depending on where it is called from.
So if I want my addNewItem() method up in G, where the ArrayList is generic, how do I add a new B,C,D or E object to it w/o the casting I showed?

1 month ago
I just have to laugh and shake my head ..... I remember now why I rarely post to forums with questions - because everyone is much more interested in criticizing, second guessing, and going off on tangents than they are in actually answering the question - gotta prove how smart they are and how dumb I am I suppose LOL. It's like - you ask how to put gas in your lawnmower, and everyone starts telling you you've got the wrong kind of yard, and do you really need a lawnmower, and why is your lawnmower red and not green, etc. etc. etc.

In the responses - I got one that was almost helpful -  partially- and the rest?... well see the above.

Here's the thing. the code SAMPLE I gave in the OP was just that - a SAMPLE. It is not the real code I'm working with which is much more involved, lengthy, etc. and involves multiple classes, sub-classes, etc. I simply (or so I thought) wrote a little sample code fragment to illustrate the SPECIFIC casting issue I was having. I was not looking for a code or design review.

But, to answer a couple of the questions anyway:
- The DAO would be a super class for specific DAO objects. It will need to process multiple different "Row" objects which themselves are sub-classed from a generic row class - that's why it's generic.
- I use "Row" because I'm a database-centric guy. To me the DAO is simply a table-cursor and the instances of the object in the array represent "rows" of that table-cursor. That's how I think and it works just fine. This object will be populated from a ResultSet.
- Inner Class? I dunno - just came out that way in the sample code. Not relevant to the issue, and I rarely/never use them in real life. Again S-A-M-P-L-E

Here's the thing - no one actually answered the problem which was a casting issue. The "right" answer, which I discovered on my own (an IDE suggestion actually I missed before) was that I need to have:

That simple. That's all I needed. My NEW question becomes, I thought one of the points of generics was to avoid the old style of casting like that? I would have expected something more like:

If anyone has thoughts on THAT specifically, I'd love to hear them.

Thanks -shields up ...

1 month ago
Hi - very new to java and I'm still struggling with generics - the syntax more than the concepts i think, but anyway ....

here is my sample code:

In the method addRow() line 15, I'm getting a compiler error where noted. I'm confused because daoArray should already BE an array of type "Row" from the constructor right?  Please advise and THANKS!

1 month ago
Actually, although I haven't fully explored it, the cached data set is doing much of what I want and expect. My initial impression is that I'll be able to make that work. Thanks for the replies! I'm certainly open to any other ideas.

Carey Brown wrote:I'm a bit unclear as to what you are trying to do. It sounds like you are trying to use a ResultSet as a collection that you can manipulate. In my experience a ResultSet is best treated as read-only and that the ResultSet should be converted to a Collection (e.g. List) of a class that will hold all the columns for a row (i.e. a Data Access Object). All manipulations would then be done on the Collection you created, not the ResultSet.

I guess I am/was hoping that ResultSet or maybe a RowSet WOULD BE the kind of object I'm looking for ... yes ... a DAO. I suppose I am skewed in my expectations, having done most of my work in Visual Fox Pro many years ago that really made these things simple and straightforward. If you're not familiar with it, or other Data-Centric application development tools like Access, Delphi, Powerbuilder, 4th Dimension, etc. then you may be shaking your head, but from my point of view, being able to EASILY handle local-side data cursors with full functionality - not only in and of themselves, but being able to easily map/bind them to gui objects with just some property settings and little to no code, is kind of application development 101 in my mind. i'm just sort of stunned that a language as mature and widespread as Java (and others BTW) doesn't have this baked into the core language.

Ok SoapBox off - having said that, I guess I'll have to look at finding some sort of library or rolling my own as you pointed out.

Hi - just getting back into java after a hiatus for a year.

For the life of me, ResultSets don't make sense to me. First of all, I'm quite familiar with dealing with cursors and data-table object in other languages, but the behavior of the RS has me stumped. i have no problem connecting and retrieving data or scrolling through, displaying my data on a simple form, etc. My problem is updating. Specifically:

When I updateString() and then immediately check what i just did with getString(), the old/original value is still there? If I updateRow, the new value then shows up, but how can I get the new/current value before or without updating the back-end database? obviously it is there somewhere, because updateRow send it to the database, but how can i retrieve it independently?


1 month ago
OK - here's my "real"code I actually got working (or at least compiling - it doesn't actually do anything useful yet).

The line " returnValue  = returnType.newInstance();" is just a stub to make something happen. In real life, I will be running a more complex method on another object to get back a "returnType" object. Other branches of the if/else (or likely a switch statement) will return different class objects.

You might have hit on my next question though, which is what to do if the calling program/method DOESN'T KNOW the return type either? For example, this is actually a part of a chain of responsibility pattern I'm trying to implement, and the calling method may not know the type, and the thing that called it may not know either for that matter. I know at the beginning of the chain, the initial calling method will know, and at the end, whatever parses it out will figure out the right thing to "make" and send back, but there could be several proxy objects/methods in between that just need to just "pass the message along" w/o concern for a specific return type.

1 year ago
Still new at this java thing ...

I'm trying to get my head around generics, as i see a lot of potential uses for it, but it seems like all the examples are based around collections and looping around them and such. I'm trying to do something simpler like my example here (of course this won't run - consider it quasi-code - but it should get the point across of what I'm trying to do hopefully.) I'm trying to return an object that can be one of many types depending on the parameter passed in (an enum value in this case). Any help is greatly appreciated!

1 year ago

Paul Clapham wrote:I usually find that asking why something is implemented in a particular way is fruitless -- even if you find out, it's still going to be implemented in that way. In the end you have to write your code to match the implementation of that thing anyway.

granted ... but can you tell me anyway, in line 3, i can call something to tell me that "Alice" is now the current/pending value for that field in that row? Thanks!
I'll have to check out next week - gonna be out for several days here ... THANKS!

Paul Clapham wrote:Actually, after I read the API docs, I found out that Oracle's RowSet tutorial tells you to do exactly what I suggested. It doesn't mention com.sun classes at all.

(I always by preference read the Oracle tutorials before anybody else's tutorial.)

isn't JdbcRowSetImpl  from the sun library?
Hi ... so i have a result set "rs" ... CONCUR_ UPDATEABLE and SCROLL-SENSITIVE ...  can anyone explain this behavior to me?

current row has column firstname ... value "Bob"

1. System.out.println(rs.getString("firstname"));  ..... prints "bob" as expected
2. rs.updateString("firstname", "Alice");  runs, no errors
3. System.out.println(rs.getString("firstname"));  ..... still prints "bob"???
4. rs.updateRow(); ... runs, no errors ... database is updated to "Alice" as it should be
5.  System.out.println(rs.getString("firstname")); it prints "Alice" - which is correct

So the questions is, why did i have to update the database with updateRow() before getString() would return the correct new value from the ResultSet? And where is "Alice" stored until I updateRow() ?? IOW, how do i get something to retrieve and print "Alice" in line 3?


Paul Clapham wrote:

But you might want to try addressing the "limitations" you found in some other way. Would you like to ask that question here?

Hi thanks! Well - the specific limitation I was trying to overcome is a way to "revert" a row in my ResultSet back to it's original values w/o having to go back to the database. I don't see a way in a ResultSet , but a RowSet seems to support this?

also - the idea of being able to use a RowSet in disconnected mode and only reconnect when time to update the back-end seems like a positive for my situation that a ResultSet can't really do?

Still learning here ...

I have my little app's first form/screen working with a ResultSet from my database. After running into some limitations, my research yielded that perhaps I should be using RowSets instead. The issue seems to be that all the implementation classes are part of Sun libraries that I'm warned not to use in an application because it is an "internal proprietary API and may be removed in a future release".

Every example I see uses these. In fact, some point out the warning, and then tell you how to do it? I'm confused ... it's like it's saying "here's how to use RowSets, and by the way, don't use RowSets." Please help - if I want to use RowSets, is there some "correct" way to do it that is different than these examples? How do I create RowSet instances w/o using those Sun libraries?