Guest User

Untitled

a guest
Mar 7th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
  2. static final String URL = "jdbc:mysql://localhost:3306/Connection?autoReconnect=true&useSSL=false";
  3. static final String NAME = "root";
  4. static final String PASS = "pass";
  5.  
  6. Connection connect = null;
  7. Statement statement = null;
  8.  
  9. System.out.println("Registering JDBC driver...");
  10. Class.forName(JDBC_DRIVER);
  11.  
  12. System.out.println("Creating database connection...");
  13. connect = DriverManager.getConnection(URL,NAME,PASS);
  14.  
  15. System.out.println("Executing statement...");
  16. statement = connect.createStatement();
  17.  
  18. String sql;
  19. sql = "SELECT city, target, sales FROM offices";
  20.  
  21. ResultSet resultSet = statement.executeQuery(sql);
  22. while(resultSet.next()){
  23. String city = resultSet.getString("city");
  24. Double target = resultSet.getDouble("target");
  25. Double sales = resultSet.getDouble("sales");
  26.  
  27. System.out.println(city);
  28. System.out.println(target);
  29. System.out.println(sales);
  30. }
  31. resultSet.close();
  32. statement.close();
  33. connect.close();
  34. }
Add Comment
Please, Sign In to add comment