fork download
  1. public static void viewTable()
  2. {
  3. Statement stmt=null;
  4. String query= "select * from table_name";
  5. Try
  6. {
  7. //con is Connection Object
  8. stmt=con.createStatement();
  9. ResultSet rs=stmt.executeQuery();
  10. while(rs.next())
  11. {
  12. System.out.println(rs.getString(1));
  13. }
  14. }
  15. catch(SQLException e)
  16. {
  17. e.printStackTrace();
  18. }
  19. finally
  20. {
  21. if(stmt!=null)
  22. {
  23. stmt.close();
  24. }
  25. }
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
public static void viewTable()
              ^
Main.java:5: error: class, interface, or enum expected
	String query= "select * from table_name";
	^
Main.java:6: error: class, interface, or enum expected
	Try
	^
Main.java:10: error: class, interface, or enum expected
ResultSet rs=stmt.executeQuery();
^
Main.java:11: error: class, interface, or enum expected
while(rs.next())
^
Main.java:14: error: class, interface, or enum expected
	}
	^
Main.java:19: error: class, interface, or enum expected
			}
			^
Main.java:25: error: class, interface, or enum expected
				}
				^
8 errors
stdout
Standard output is empty