Advertisement
Guest User

Untitled

a guest
Jun 15th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. /**
  8. *
  9. * @author 10154282
  10. */
  11. import static java.lang.System.out;
  12. import java.sql.*;
  13. import java.text.NumberFormat;
  14.  
  15. class GetData {
  16.  
  17. public static void main(String args[]) {
  18.  
  19. NumberFormat currency =
  20. NumberFormat.getCurrencyInstance();
  21.  
  22. final String DRIVER = "com.mysql.jdbc.Driver";
  23. final String CONNECTION =
  24. "jdbc:mysql://busman.britafe.vic.edu.au/DB_jarrods?" +
  25. "user=jarrods&password=jarrod";
  26.  
  27.  
  28. try {
  29. Class.forName(DRIVER).newInstance();
  30. } catch (InstantiationException e) {
  31. e.printStackTrace();
  32. } catch (IllegalAccessException e) {
  33. e.printStackTrace();
  34. } catch (ClassNotFoundException e) {
  35. e.printStackTrace();
  36. }
  37.  
  38.  
  39. try (Connection connection =
  40. DriverManager.getConnection(CONNECTION);
  41.  
  42. Statement statement =
  43. connection.createStatement();
  44.  
  45. ResultSet resultset =
  46. statement.executeQuery(
  47. "select * from ACCOUNTS")) {
  48.  
  49. while(resultset.next()) {
  50. out.print(resultset.getString("NAME"));
  51. out.print(", ");
  52. out.print(resultset.getString("ADDRESS"));
  53. out.print(" ");
  54. out.println(currency.format(
  55. resultset.getFloat("BALANCE")));
  56. }
  57. } catch (SQLException e) {
  58. e.printStackTrace();
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement