Advertisement
Guest User

Untitled

a guest
Feb 5th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. public void connect () {
  2.     try{        
  3.           Class.forName("com.mysql.jdbc.Driver");
  4.           String servername = "potsdam-moodle.de";
  5.           String datenbank = "e209123";
  6.           String url = "jdbc:mysql://" + servername + "/" + datenbank;
  7.           String username = "e209123";
  8.           String password = "Wh3c#3a3";
  9.           Connection connection = DriverManager.getConnection(url, username, password);  
  10.       } catch  (Exception e){
  11.             e.printStackTrace();
  12.             System.out.println("Error" + e);
  13.        }  
  14. }
  15.  
  16. public void update(Float preis, String spalte) {
  17.     try {    
  18.         connect();
  19.         String query = "Update Produkte SET Preis= ? Where Name= ?";  
  20.         PreparedStatement st = connection.prepareStatement(query);            
  21.         st.setFloat(1,  preis);
  22.         st.setString(2, spalte);
  23.         st.executeUpdate();
  24.       }
  25.       catch  (Exception e){
  26.         e.printStackTrace();
  27.         System.out.println("Error" + e);
  28.     }  
  29. }
  30.  
  31. tableView2Column2.setOnEditCommit(new EventHandler<CellEditEvent>() {   //Anfang
  32.       public void handle(CellEditEvent t){
  33.         update(Float.parseFloat(""+t.getNewValue()), ((Produkt) t.getTableView().getItems().get(t.getTablePosition().getRow())).getName());
  34.     }
  35.   }        
  36. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement