|
|
|
| |||||||||
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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.... |
|
#2
|
||||
|
||||
|
do a query for rowcount...if the rowcount is 0 then it is probably not there...
|
|
#3
|
|||
|
|||
|
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); } } |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > checking if data exist in database |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|