56. How can you retrieve data from the ResultSet


Statement stmt = conn.createStatement(); 
ResultSet rs = stmt.executeQuery(SELECT COF_NAME, PRICE FROM COFFEES”); 
while (rs .next() ) 

//Iam assuming there are 3 columns in the table. 
System.out.println ( rs.getString(1)); 

//don’t forget to close the resultset, statement & connection 
rs.close(); //First  
stmt.close(); //Second 
con.close(); //Last  
System.out.println(“You are done”); 


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: