Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if no records found 1

Status
Not open for further replies.

jass1220

Programmer
May 20, 2003
88
AE
i want to have if condition after this query .. this condition is if there is no record found the session should be "" and error msg else the session = the username of the record found (actually this code for checking the login)

//////////

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection connection = DriverManager.getConnection("jdbc:eek:dbc:ClassMates");
Statement statement = connection.createStatement();
ResultSet columns = statement.executeQuery("select * from mates where username ='"+strUser+"'");

/////////
 
Please view the other question you posted, I think you are misunderstanding the correct usuage of session objects ... Maybe somthing like this will help :

Code:
  i want to have if condition after this query .. this condition is if there is no record found the session should be "" and error msg else the session = the username of the record found (actually this code for checking the login)
[code]
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection connection = DriverManager.getConnection("jdbc:odbc:ClassMates");
  Statement statement = connection.createStatement();
  ResultSet columns = statement.executeQuery("select * from mates where username ='"+strUser+"'");

  String dataFound = "";

  while (rs.next()) {
     // add in what you want from the ResultSet ...
    // this just gets the first column
     dataFound += (rs.getString(1) +" ");
  }

  // if nothing was returned from the sql ...
  if ((dataFound.trim()).equals("")) {
     dataFound = "Sorry, no data found ...";
  }
 
its working fine .. thanks a lot :) .. so great
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top