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)); System.out.println(rs.getString(2)); System.out.println(rs.getString(3)); } //don't forget to close the resultset, statement & connection rs.close(); //First stmt.close(); //Second con.close(); //Last System.out.println("You are done");
Connection con=null;ResultSet rs=null;//write your own code for Making connection to ur databaseString Query="Select * from emp";try{Statement stmt=con.CreateStatement(rs=stmt.executeQury(Query);while(rs.next(){ System.out.println(rs.getString(1)+" "+rs.getString(2));stmt.close();rs.close();}catch(Exception e){ System.out.println(e.getMessage());}finally{ try { if(con!=null) con.close(); } catch(SQLException e) { System.out.println(e.getMessage());}
Please Note: We keep on updating better answers to this site. Subscribe to our newsletter to get notified when better answer is posted.
Copyright ©2003-2010 CoolInterview.com, All Rights Reserved. Privacy Policy | Terms and Conditions Page URL: http://www.coolinterview.com/interview/5015/default.asp?cachecommand=bypass