Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. static private String database = "fuhrpark";
  2. static private String conn = "jdbc:mysql://localhost/";
  3. static private String user = "root";
  4. static private String password = "";
  5.  
  6. static private Connection connection;
  7.  
  8. static Connection getConnection()
  9. {
  10. if (connection==null)
  11. {
  12. try
  13. {
  14. // lade Treiberklasse
  15. Class.forName("com.mysql.jdbc.Driver");
  16.  
  17. // erzeuge Verbindung zur DB mit den angegebenen Daten
  18. connection = DriverManager.getConnection(conn+database+user+password);
  19. }
  20. catch (ClassNotFoundException e)
  21. {
  22. e.printStackTrace();
  23. }
  24. catch (SQLException e)
  25. {
  26. e.printStackTrace();
  27. }
  28. }
  29. return connection;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement