Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. //metoda w servlecie
  2.  
  3. baza.przelew(connection,"Jacek","Kapusta",5000);
  4.  
  5.  
  6. //cialo metody
  7.  
  8. public void przelew(Connection connection,String nazwisko,String nazwisko2,int ile){
  9.  
  10. int x=ile*(-1);
  11. baza.updatekonto(connection,"Kapusta",ile);
  12. baza.updatekonto(connection,"jacek",x);
  13. baza.updatehistoria(connection,"Kapusta","Jacek",ile);
  14. baza.updatehistoria(connection,"Jacek","Kapusta",x);
  15. }
  16.  
  17.  
  18.  
  19.  
  20.  
  21. //cialo updatekonto
  22.  
  23. public static void updatekonto(Connection connection, String nazwisko, int ile){
  24.  
  25. String b="";
  26. Statement stmt = null;
  27. try {
  28. stmt = connection.createStatement();
  29. } catch (SQLException e) {
  30. e.printStackTrace();
  31. //writer.println("NIE CHODZE1sql");
  32. }
  33. try {
  34.  
  35. String a="Update konto set kasa=kasa";
  36.  
  37. if(ile>=0){
  38. b="+";
  39. b+=String.valueOf(ile);
  40.  
  41. }
  42. else{
  43. //b="-";
  44. b+=String.valueOf(ile);
  45. }
  46.  
  47. String c=" where nazwisko='";
  48. c+=nazwisko;
  49. c+="';";
  50.  
  51. //String d=a+b+c+;
  52.  
  53. stmt.executeUpdate(a+b+c);
  54.  
  55.  
  56. } catch (SQLException ex) {
  57. ex.printStackTrace();
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. //cialo upddadtehistoria
  68.  
  69.  
  70.  
  71.  
  72.  
  73. public static void updatehistoria(Connection connection, String nazwisko, String nazwisko2, int ile){
  74.  
  75. String b="";
  76. Statement stmt = null;
  77. try {
  78. stmt = connection.createStatement();
  79. } catch (SQLException e) {
  80. e.printStackTrace();
  81. System.out.println("error1");
  82. //writer.println("NIE CHODZE1sql");
  83. }
  84. try {
  85.  
  86. String a="Insert into historia values('";
  87. b=nazwisko+"','"+nazwisko2+"',"+String.valueOf(ile)+");";
  88.  
  89.  
  90. System.out.println(a+b);
  91.  
  92. //String d=a+b+c+;
  93.  
  94.  
  95. stmt.executeUpdate(a+b);
  96.  
  97. } catch (SQLException ex) {
  98. ex.printStackTrace();
  99.  
  100. System.out.println("error2");
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement