Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. public static void letsGo(){//UPDATE
  2. con=null;
  3. try{
  4. con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/","SA","");
  5. stmt = con.createStatement();
  6.  
  7.  
  8. ResultSet rs = stmt.executeQuery("select buchnr, autor from buecher, autoren where buecher.isbn = autoren.isbn");
  9. while(rs.next()){
  10. int buchnr = rs.getInt(1);
  11. String autor = rs.getString(2);
  12.  
  13. if(buchnr != altNr){
  14.  
  15. altNr = buchnr;
  16. altAutor = autor;
  17. }
  18. else{
  19.  
  20. System.out.println("UPDATE zweiautor set autor = '"+autor+", "+altAutor+"' where buchnr = "+altNr+" AND autor = '"+altAutor+"'");
  21. stmt.executeUpdate("UPDATE zweiautor set autor = '"+autor+", "+altAutor+"' where buchnr = "+altNr+" AND autor = '"+altAutor+"'");
  22. System.out.println("DELETE FROM zweiautor WHERE buchnr = "+buchnr+" AND autor = '"+autor+"'");
  23. stmt.executeUpdate("DELETE FROM zweiautor WHERE buchnr = "+buchnr+" AND autor = '"+autor+"'");
  24.  
  25. }
  26. }
  27. }
  28. catch(SQLException e){
  29. e.printStackTrace();
  30. }
  31.  
  32. }
  33.  
  34. public static void letsRock(){//INSERT
  35. con=null;
  36. try{
  37. con = DriverManager.getConnection("jdbc:hsqldb:hsql://localhost/","SA","");
  38. stmt = con.createStatement();
  39.  
  40. ResultSet rs = stmt.executeQuery("select buchnr, autor from buecher, autoren where buecher.isbn = autoren.isbn");
  41. while(rs.next()){
  42.  
  43. int buchnr = rs.getInt(1);
  44. String autor = rs.getString(2);
  45.  
  46. stmt.executeUpdate("insert into zweiautor values("+buchnr+",'"+autor+"')");
  47. System.out.println("insert into zweiautor values("+buchnr+",'"+autor+"')");
  48.  
  49. }
  50. }
  51. catch(SQLException e){
  52. e.printStackTrace();
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement