Mike McMahon

Ranch Hand
+ Follow
since May 07, 2005
Merit badge: grant badges
For More
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Mike McMahon

Alas - My sql was botched. I ran it directly (through iSQLPlus) and found an error. I guess Java was right, and i was pointing at null!
Hey Folks,
I'm trying to handle cases where a query results in no results. Instead of an error page, I'd like a friendly message.

Here's what I have:


I found this snippet out on the net, and it looks simple, but I'm getting a nullpointerexception on the line with if (rsStns.next()) {

Am I missing something obvious?

Cheers,
Mike
Thanks -
I'm aware of SQL injection attacks, and am taking measures with my queryText variable prior to executing it.

On another note, all of this talk of standards compliance seems to have taken over this thread, when the original question asked about returning variables that had been captured. I appreciate the comments, but nothing works right now, compliant or not!

Thanks,
Mike

Originally posted by Paul Clapham:
You normally wouldn't parse any SQL queries. ("Parsing" is the act of translating a text format into an internal data structure, so parsing an SQL query is what the database driver does.)

But if you're asking whether it's a good practice to construct an SQL query from some base text and some parameters, like this:
then no, that isn't a good practice. It leaves you open to SQL injection attacks (you could look that up). The better practice is to use a PreparedStatement for your SQL:

15 years ago
Is it bad form to parse a SQL query from data collected by a form on a JSP page? The query is being performed within my getProducts.java class. I don't think I'm breaking any rules...

Originally posted by Bear Bibeault:
This actually applies to any web application, Struts-based or otherwise. It's considered a very poor practice.

15 years ago
Hey Merrill,

Thanks for the note - I figured out what they were called. Thanks also for the tips. I am writing JSP however - The query text I've gotten there is information gathered from a form, and then I'm going to instantiate a class, using the query as a constructor.

If you're aware of a way to have my EL expressions replaced with their variables, I'd still love to know. Thanks so much!

Mike

Originally posted by Merrill Higginson:
Those "thingies" are called EL (Expression Language) Expressions. Their purpose is to translate data that exists in JavaBean object into a form that can be displayed on a JSP page. For example, the EL expression ${myBean.foo} is similar to writing <%= myBean.getFoo() %>.

Since you're writing Java code instead of a JSP page, EL expressions aren't going to be of much use to you. You will want to use the equivalent Java exressions to retrieve the data. Example:


[ July 02, 2008: Message edited by: Merrill Higginson ]

15 years ago
Hey folks,

I know this question is very straightforward, but since I don't know what you call data in the form of

I haven't been able to search google. My book is at home, and I'm at work, so I'm kind of stuck.

Anyways, I have a bunch of variables in my app stored using the format shown above, and now I'm trying to put it all together and parse a query using those variables. Something like:


Needless to say, the ${*.*} thingies were not replaced with my stored values, so my query is failing. I tried some silly little things like:


but I'm at a loss.

And what do you call those thingies anyways?!

[ July 02, 2008: Message edited by: Mike McMahon ]
[ July 02, 2008: Message edited by: Mike McMahon ]
15 years ago
Thanks guys - I'll just add here for other noob's in case they stumble against a similar problem. My methods were not public (they were static), hence they could not be pulled out and my loop just kept returning the last record again and again and again...

Mike
16 years ago

Originally posted by Campbell Ritchie:
... Your repeated = null calls are redundant; your local variable will vanish when the method completes anyway...


Thanks Campbell,

The reasoning for the null calls was that I thought that as each object was pulled from the array, I would set it to path_get while I wrote it out the information, then I would clear out the path_get object so that as the loop populated it with new information (from the next value in the arraylist, it would be writing to an empty object.

---Mike's Edit---
Hmmm - it may be that I have just loaded the arraylist incorrectly, and loaded it up with identical objects... I will look into that before I ask too much of you guys...

Thanks,
Mike
[ January 24, 2008: Message edited by: Mike McMahon ]
16 years ago
Hi -
I have loaded up an array list with objects, and I am trying to pull out some information from them within a loop using the loop below. My result is that I get a tone of information spewed into my output, but it loooks like it is the same information repeated x number of times, where x is the number of items in my arraylist.

I was hoping that it would go to arraylist item1, give me the getName and the getDate, then do the same for all the sequential records.

This has to be some obvious oversight....

16 years ago
Hey Everyone,

I've been playing with the generalPath class, and am happy with how it works. I had previously looked at the awt.geom.Polygon class, but didn't like that it didn't accept floats.

Now that I'm using the generalpath class, I've noticed a big disadvantage from the polygon class - there's no npoints() method!. This method tells me how many points are in the path. I need to know this, because points (n=1), lines (n=2) and polygons (n>2) all need to be treated differently.

I've currently got, the following working - but it seems clunky. Can anyone either confirm that this is a good way to approach this, or suggest an alternative?

16 years ago

Originally posted by Pho Tek:
This is how you would do it:



Aaaaaaahhhhhh!!! Thanks - that's super!!
16 years ago

Originally posted by Ernest Friedman-Hill:
Yes, people do indeed do that sort of thing sometimes. Be careful, because that number you give is only about a factor of 20 smaller than the largest positive int value; otherwise you'll get overflow.



Thanks for the warning - I checked my data, and I know the maximum amount, and it still falls within the int range (thank goodness!).

It seems to make sense that I should impose my multiplication at the addPoint event, and I'm not sure how to do that. When Pho was explaining he described the following for overriding an existing classes method:

What I don't understand here is that it seems to suggest going into that overridden class (polygon, above, with ix and iy) and changing things. I must be misinterpreting.

I think what I need to do is something like

Obviously this is wrong (since I just tried it...). I think I'm still at ground zero regarding overriding methods. Are there any FAQs?

Thanks!
16 years ago
Hey Vijay -
Thanks - that's helpful for most aspects of my objects arrayList.

Pho was helping me with the more troublesome part where I've got an object loaded into the arraylist that I apparently need to RTM to learn how to override the toString() method to get my values back out of it.

Thanks for your help!
Mike
16 years ago

Originally posted by Pho Tek:

All Classes automatically inherit from Object.
Since you've not overriden the Object#toString() method, it uses that when you pass an instance of myPolygon to System.out.println( .. ).

In summary, implement myPolygon#toString to print out all the points and name.



I don't think I understand - I've added "out.println(p_charts.toString());" (where p_charts is the name of my arraylist), and my output is "[GoogleDir.chsPolygon@1bbd3e2, GoogleDir.chsPolygon@53abbb]"

I really appreciate your help - but could you clarify?
[ January 08, 2008: Message edited by: Mike McMahon ]
16 years ago
OK - that's a bit dramatic...

I've got a whole bunch of objects with stuff in common, and I don't know how many there will be, so I thought an arraylist would be a handy way to organize them. I have loaded it like so:

The problem is -- I don't know how to retrieve all of my data from my objects. I've looked around and found people who have suggested something like the following:

This outputs "GoogleDir.chsPolygon@6b62d1" - which I don't quite understand. If you are so kind as to point me in the right direction, what I'd love is something I could throw into a loop that would allow me to pull out all of the info from all of my objects.

Thanks ever-helpful friends,
Mike
16 years ago