Ken Matson

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

Recent posts by Ken Matson

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.

4 months 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!

4 months 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"));  .....now 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?

Thanks,
KenM


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?

thanks!
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?

TIA!
OK - coming along in my Java education, and appreciate help I've received here! I have always been a "data centric application" programmer, and I'm really struggling trying to find tutorials on how to do simple (or what should be simple) binding of form controls to data in a ResultSet. Here's what I'm looking to do.

I can successfully retrieve data from my database (PostgreSQL), and store that result set on my form controller. My form is a simple data maintenance form  - let's say an "Employee" form. I have  text fields for first name, last name, and title. I know I can manually set the text of those text fields to equal the corresponding column (of the current row) in my ResultSet, however, got to be a better way right? What I want to do is BIND the value of each textfield to a column of the result set so that anytime I change the row of the result set, all the textfields automatically update, and so that if I type in a textfield, it auto-updates the corresponding row/column in the ResultSet. I'd have Next and Previous buttons on the form to move to the next/prev row and expect the form to refresh accordingly to display the current row's data.

To me - perhaps because of my background, this is the very most basic, "form 101" thing you can do in an application, so I'm surprised I can't find anything with a simple, straightforward tutorial on it? Please help!

THANKS!

5 months ago
Thanks. I got it figured out by setting the classpath in netbeans. I was getting frustrated because all the research I did kept telling me the set the classpath, and nobody told me how to actually do it.
Ok - new to java and this is killing me - wither my brain quit working or I'm missing something basic.

I downloaded and installed PostgreSQL - I created a new database , tables,, and added data via the management tool that came with it ... pgAdmin4 ... all is happy there.

When I try to connect from my code, I get a "No suitable driver found for jdbc:postgresql://localhost/mydatabase" error. My research finds a lot of talk about "Classpath" and "registering driver". I'm confused as I Dont know what/how to work with those things. Do i need to move the driver somewhere? Do I need to point to the driver from my code? Heck - what is even the name of the driver file and how do i find it? I'm really lost.... sorry!

Thanks for any help!
I got it figured out thanks to some online searches. Basically what I'm doing is getting a reference to the controller for the form, and referencing variables there through getters. The buttons themselves Can update the variables. Thanks for the help everyone!
6 months ago
Hi,

Just learning JavaFx and Scene Builder. So I'm successfully presenting a simple form which was designed in Scene Builder. It has several buttons, all of which simply close the form. Great - they work fine. What I need to know is how the method that called/opened this form can know which button was clicked? eg how do I pass back which button was clicked to the calling program?

THANKS!
6 months ago

Chris R Olsen wrote:Ken --

  I was in your shoes a couple years ago!

  What saved me was the book, Learn Java FX 8 by Kishori Sharan.  It is totally marvelous!

  A decision I made, which you may or may not, was to NOT use the SceneBuilder until I had a clue what was happening under the hood.  (Here is where the Sharan book was really good for me).  I still, a couple years later, do not use the SceneBuilder, but I suppose I might in the future.

  -- Chris

 



Thanks - I'll take a look. At the moment - I've just kind of looked at all this as a "black box" and am putting my code in it. At least I'm making progress on my app that way!
6 months ago
THANKS! Works well
6 months ago