Advertisement
Guest User

Untitled

a guest
May 10th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1.  
  2. private Connection conn;
  3.  
  4.  
  5. public static void connectMYSQL() {
  6.  
  7. try {
  8. System.out.println("Verbindung zur Datenbank wird hergestellt!");
  9. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb?" + "user=testuser");
  10. System.out.println("Verbindung zur Datenbank hergestellt!");
  11. } catch (SQLException e) {
  12. System.out.println("Es gab einen Fehler!");
  13. e.printStackTrace();
  14. }
  15.  
  16. }
  17.  
  18.  
  19. public static void update(String up) {
  20. try {
  21. Statement s = conn.createStatement();
  22. s.executeUpdate(up);
  23. s.close();
  24. } catch (SQLException e) {
  25. e.printStackTrace();
  26. }
  27. }
  28.  
  29. public static ResultSet query(String up) {
  30. ResultSet r = null;
  31.  
  32. try{
  33. Statement s = conn.createStatement();
  34. r = s.executeQuery(up);
  35. }catch(SQLException e) {
  36. e.printStackTrace();
  37. }
  38. return r;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement