Advertisement
Guest User

Untitled

a guest
Jun 14th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. static void getHighScores() {
  2. try {
  3. Class.forName("oracle.jdbc.driver.OracleDriver");
  4. } catch (ClassNotFoundException e) {
  5.  
  6. System.out.println("Where is your Oracle JDBC Driver?");
  7. e.printStackTrace();
  8. return;
  9. }
  10. Connection connection = null;
  11. try {
  12. connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "STUDENT", "STUDENT");
  13. } catch (SQLException e) {
  14. System.out.println("Connection Failed! Check output console");
  15. e.printStackTrace();
  16. return;
  17. }
  18. try {
  19. Statement stmt = connection.createStatement();
  20. ResultSet rs = stmt.executeQuery("SELECT * FROM HIGHSCORE ");
  21. System.out.println("Top Players");
  22. while (rs.next())
  23. System.out.println(rs.getString(1) + " " + rs.getInt(2));
  24. connection.close();
  25. } catch (Exception e)
  26.  
  27. {
  28. System.out.println(e);
  29. }
  30. }
  31.  
  32. connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521/xe", "STUDENT", "STUDENT");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement