Web Hosting Talk







View Full Version : Java Result Set Question


cosmic_bird
03-28-2003, 07:56 AM
I want to get the value of an element in a result set.

For example

"SELECT * FROM table WHERE field= 4th element";

How do I get the 4th element?

digitok
03-28-2003, 08:00 AM
Umm, you've said Java, but to me that looks like some MySQL, and also, what do you mean by "the fourth element" like "this is a test this is a" would return "test" ? Or do you mean the fourth row in the table? A little more info please :)

cosmic_bird
03-28-2003, 08:03 AM
Sorry I wasn't clear. You;re right it's not java, it is SQL. And I want the 4th column in the table.

digitok
03-28-2003, 08:07 AM
Umm, well I don't know the name of the fourth column
but I'm _guessing_ you're wanting something like this:

// replace "blah" with the name of the 4th column
// also replace "table" with the table name
// and replace "whatever" with what you need it to match with
mysql_query("SELECT blah FROM table WHERE blah='whatever'");

digitok
03-28-2003, 08:08 AM
If that's not what you wanted, just reply with some more info and I'll try again :)

cosmic_bird
03-28-2003, 08:15 AM
i'll explain exactly what my dilema is.
I'm parsing newsfeeds in a java class that runs every 5 mins. These news stories go into a table. The only unique field in each row (news story) is the "link" field.

I insert the parsed news feed like so:

stmt.executeUpdate("INSERT INTO news_item VALUES (" + DBQuote.parse(title) + "," + DBQuote.parse(link) + "," + DBQuote.parse(sDate) + "," + DBQuote.parse(source) +")");


Now what I want to do is say if 'link' is already in the table do not insert this news story else do insert.

I need to do this because I would get duplicated stories in my table.

So before I insert the the parsed news story I need to have some kind of if statement.

Any ideas?

digitok
03-28-2003, 08:26 AM
ahh, I see what you mean.
ok, well I don't know much JS, but, in PHP it'd be something like:

// replace "blah" with the variable holding the link
$q = mysql_query("SELECT * from news_item WHERE link='blah'");
$r = mysql_num_rows($q);
if (!$r) {
// insert the stuff cuz the link doesn't match
}
else {
// do something because the link is already there
}

Now, as I said that's like in PHP, so you're gonna have to
make it into java using your weird functions, etc.

cosmic_bird
03-28-2003, 08:30 AM
Thanks a alot that gives me a good idea!

digitok
03-28-2003, 09:13 AM
No probs, glad to be of assitance :)

jb4mt
03-28-2003, 10:36 AM
Did the previous replies help? Cause I have specific Java/JDBC experience from my last job (resume online at http://resumes.hotjobs.com/codesnob/2003)

Lemme know....

cosmic_bird
03-28-2003, 12:00 PM
Yeah thanks it work okay!