Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vsa;
- import java.sql.*;
- public class VSA {
- public static double cenaKnihy(String meno) throws ClassNotFoundException, SQLException {
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery("SELECT * FROM APP.KNIHA WHERE KNIHA.NAZOV = '" + meno + "'" );
- while(rs.next()) {
- return rs.getDouble(3);
- }
- System.out.println("Knihu nemame");
- return 0;
- }
- public static boolean pridajKnihu(String meno, Double cena) throws ClassNotFoundException, SQLException {
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
- Statement st = con.createStatement();
- ResultSet rs = st.executeQuery("SELECT * FROM APP.KNIHA WHERE KNIHA.NAZOV = '" + meno + "'" );
- if(!rs.next()){
- st.executeUpdate("INSERT INTO APP.KNIHA (NAZOV,CENA) VALUES ('" + meno + "'," + cena+")");
- return true;
- }
- return false;
- }
- public static void zlava(String meno) throws ClassNotFoundException, SQLException {
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/sample", "app", "app");
- Statement st = con.createStatement();
- st.executeUpdate("UPDATE APP.KNIHA SET CENA = CENA*0.8 WHERE NAZOV = '" + meno + "'");
- }
- public static void main(String[] args) throws ClassNotFoundException, SQLException {
- System.out.println(cenaKnihy("test"));
- pridajKnihu("novakniha",99.0);
- zlava("test");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement