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 IamaSherpa 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 the database

Status
Not open for further replies.

flyclassic22

Technical User
Oct 1, 2002
54
SG
May i know how can i abstract every data from all the rows under a specific column?

When i use this SQL query statemnt, "SELECT Name FROM StudentRecord", this will return ROWS of record under the column "Name". So if i want to store every data into a variable, how can i do it?

When i use this SQL query statement, "SELECT * FROM StudentRecord WHERE Name="Hello", and if in the database there isnt a record with the "Name" as "Hello", will ResultSet return a null and how can i handle this error?

Please direct me. Thanks
 
You can try writing all of the fields in your db table
for example there are 4 fields (name,surname,number,id )
the you can try typing (select name,surname,number,id from (your table name> ).

the result set WILL NOT return null.
resultSet.getString,getInt,getDouble of course will return null but the class itself is not null.To solve this ,act in this way below:
java.sql.ResultSet rs = stmt.executeQuery("your query");
while (rs.next())
{
//in that block you are sure that there is at least 1 row
//of your query
} Salih Sipahi
Software Engineer.
City of Istanbul Turkey
ssipahi@yonbilgi.com
 
hmm i don't understand..
let's say i've this to display records of my 6 field database in to JTextFields(name jtff) using sql query when i trigger a button, it will display a records whenever avaliable in the JtextFields, but how do i loop throughout the database table to check if there isn't any records and popup a message and say "record not found"
any idea? PLease advise.. thanks



public void display(ResultSet rs)
{
try {
rs.next();

int recordNumber = rs.getInt( 1 );

if ( recordNumber != 0 ) {
jtff1.setText( String.valueOf( recordNumber));
jtff2.setText( rs.getString( 2 ) );
jtff3.setText( rs.getString( 3 ) );
jtff4.setText( rs.getString( 4) );
jtff5.setText( rs.getString( 5 ) );
jtff6.setText( rs.getString( 6 ) );
}
}
catch ( SQLException sqlex ) {
sqlex.printStackTrace();
}
}
 
to be in more detail, i mean, search for the criteria for eg. "name" and it doesn't match any records, i would like to display "record not found"
 
Code:
if( !rs.next())
  System.out.println("No Records found");
else
  display(rs);

does that help?
-pete
 
wow, that's easy! hehe
thanks alottttttttttttttttttttttt!!! million thanks..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top