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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to check if a query returns any rows?

Status
Not open for further replies.

hbutt

Programmer
Apr 15, 2003
35
GB
hi, im having trouble checking to see if any rows have been returned. here is the code:

public static void CC_Validate(String a)
{
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url = "jdbc:eek:dbc:SQL_ODBC_DEMO2";
Connection con = DriverManager.getConnection (url, "username", "password");
Statement stmt = con.createStatement();

String query1 = "SELECT * FROM CC_Nums WHERE CC_No="+a;
ResultSet rs1 = stmt.executeQuery(query1);

while(rs1.next())
{
String s1 = rs1.getString("CC_No");

System.out.println(s1 + "\t");

}

stmt.close();
con.close();

}
catch (SQLException e)
{
System.err.println(e.getMessage());
}
catch(ClassNotFoundException e)
{
System.err.println(e.getMessage());
}
}




any help is much apreciated. thanks
hbutt.
 
either :

Code:
        int fetchSize = 0;
        while(rs1.next())
        {
           fetchSize++;
            String s1 = rs1.getString("CC_No");

            System.out.println(s1 + "\t");

        }
        System.out.println(fetchSize);

or using the ResultSet.getFetchSize() method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top