Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Closed Thread
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old August 23rd, 2002, 07:13 AM
peter83 peter83 is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 19 peter83 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
checking if data exist in database

in my program, i am checking if the user clicks on a certain button. if a button is clicked, i need to do a query and update the table. however, before i update the database, i need to also check if the data retrieved from the textfield already exists.

I am using the request.getParameter to get the values of the user input. after getting the values, i need to check the database to see if it already exist.

i am currently using:
if(check!="null"){xyz}

where xyz is the query.

how do i do it???
pls help asap....

Reply With Quote
  #2  
Old August 23rd, 2002, 03:48 PM
tron's Avatar
tron tron is offline
SwollenMember
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2000
Location: the master control
Posts: 234 tron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 44 m 46 sec
Reputation Power: 9
do a query for rowcount...if the rowcount is 0 then it is probably not there...

Reply With Quote
  #3  
Old August 24th, 2002, 04:09 PM
CharlesBell CharlesBell is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Vicksburg, MS
Posts: 7 CharlesBell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
In java, the results of a jdbc sql query come back in a ResultSet object. BY calling the more method of ResultSet, you can determine if the result set has any data.

A ResultSet is processed as in the following method:

/**Processes the ResultSet object passed, and creates html string text
*for display by the HTMLFrame viewer.
*/
public void displayResults(ResultSet rs){
if (rs == null) return;
String displaystring = "";
try{
// use ResultSetMetaData to check column headings
ResultSetMetaData rsmd = rs.getMetaData ();
// Get the number of columns from the ResultSetMetaData
int columns = rsmd.getColumnCount();
boolean more = rs.next();
//more will be false if there is no return data to display
if (more) {
displaystring = "<html><body>\n" + "<table>\n";
displaystring = displaystring + "<tr>\n";
for (int j=1; j <= columns; j++) {
displaystring = displaystring + "<td><b>" + rsmd.getColumnName(j) + "</b></td>";
}
displaystring = displaystring + "<tr>\n";
while (more){
displaystring = displaystring + "<tr>\n";
for (int i=1; i <= columns; i++) {
displaystring = displaystring + "<td>" + rs.getString(i) + "</td>";
}
displaystring = displaystring + "<tr>\n";
//more will change to false when the end of the result set is reached
more = rs.next();
}
displaystring = displaystring + "<table>\n" + "</h2></body></html>";
}else{
displaystring = "<html><body>SQL statement executed. No results to display.</h2></body></html>";
}
if (debug) println(displaystring);
resultsdisplay.show(displaystring);
}catch (SQLException sqlexception){
displaySqlExceptionInformation(sqlexception);
}
}

Reply With Quote
Closed Thread

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > checking if data exist in database


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway