Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. package vsa;
  2.  
  3. import java.sql.*;
  4.  
  5. public class VSA {
  6.  
  7.  
  8.  
  9. public static double cenaKnihy(String meno) throws ClassNotFoundException, SQLException {
  10.  
  11. Class.forName("org.apache.derby.jdbc.ClientDriver");
  12. Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
  13. Statement st = con.createStatement();
  14.  
  15. ResultSet rs = st.executeQuery("SELECT * FROM APP.KNIHA WHERE KNIHA.NAZOV = '" + meno + "'" );
  16. while(rs.next()) {
  17. return rs.getDouble(3);
  18. }
  19. System.out.println("Knihu nemame");
  20. return 0;
  21. }
  22.  
  23. public static boolean pridajKnihu(String meno, Double cena) throws ClassNotFoundException, SQLException {
  24.  
  25. Class.forName("org.apache.derby.jdbc.ClientDriver");
  26. Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
  27. Statement st = con.createStatement();
  28.  
  29. ResultSet rs = st.executeQuery("SELECT * FROM APP.KNIHA WHERE KNIHA.NAZOV = '" + meno + "'" );
  30. if(!rs.next()){
  31. st.executeUpdate("INSERT INTO APP.KNIHA (NAZOV,CENA) VALUES ('" + meno + "'," + cena+")");
  32. return true;
  33. }
  34. return false;
  35. }
  36.  
  37. public static void zlava(String meno) throws ClassNotFoundException, SQLException {
  38.  
  39. Class.forName("org.apache.derby.jdbc.ClientDriver");
  40. Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
  41. Statement st = con.createStatement();
  42.  
  43. st.executeUpdate("UPDATE APP.KNIHA SET CENA = CENA*0.8 WHERE NAZOV = '" + meno + "'");
  44.  
  45. }
  46.  
  47. public static void main(String[] args) throws ClassNotFoundException, SQLException {
  48.  
  49. System.out.println(cenaKnihy("test"));
  50. pridajKnihu("novakniha",99.0);
  51. zlava("test");
  52.  
  53.  
  54. }
  55.  
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement