File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Java Interview Guide
this week in the
JDBC and Relational Databases
Checking existence query?
Mr. C Lamont Gilbert
Joined: Oct 05, 2001
Oct 16, 2005 08:09:00
All I want to know is if Name is not null. I have a unique constraint on my name so I need to ensure none exists which is the same as the one I plan to use.
I am using
String qstring = "SELECT Name FROM masterFuncCnctrs WHERE Name = '" + name + "' AND ComponentID = " + component.getID() + ";";
and rs.next() to tell me if such a name exists or not. Is there a better query for this since I am not even looking at the returned name, only if it exists or not.
author & internet detective
Joined: May 26, 2003
Oct 16, 2005 16:37:00
This version is slightly more efficient because the database doesn't have to return as much data.
String qstring = "SELECT count(*) FROM masterFuncCnctrs WHERE Name = '" + name + "' AND ComponentID = " + component.getID() + ";";
Did you want a unique name in general or per component id? The unique index would do it for name only.
OCA 8 book
How To Ask Questions The Smart Way
SCEA Part 1
Part 2 & 3
Core Spring 3
TOGAF part 1
I agree. Here's the link:
subject: Checking existence query?
Query regarding JDO / KODO
How can i continue executing other SQL Statments , even if one of them fails
performance issue in kodo
doubt using resultsets and queries in servlets
Comparing parameters values with db values
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015