daily pastebin goal
21%
SHARE
TWEET

Untitled

a guest Feb 21st, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private int luoVaraus(String varaajanId, String alkupaiva, String loppupaiva) {
  2.         Connection connection = null;
  3.         try {
  4.             connection = DriverManager.getConnection("jdbc:h2:./hotelliketju", "sa", "");
  5.  
  6.             PreparedStatement stmt;
  7.             stmt = connection.prepareStatement("INSERT INTO Varaus"
  8.                     + " (varaaja_id, alkupvm, loppupvm)"
  9.                     + " VALUES (?, ?, ?)",
  10.                     Statement.RETURN_GENERATED_KEYS);
  11.  
  12.             stmt.setString(1, varaajanId);
  13.             stmt.setString(2, alkupaiva);
  14.             stmt.setString(3, loppupaiva);
  15.  
  16.             // varaajalisätään tietokantaan
  17.             stmt.executeUpdate();
  18.  
  19.             int id = -1;
  20.             ResultSet generatedKeys = stmt.getGeneratedKeys();
  21.             // haetaan id vain mikäli tulostaulussa on rivi
  22.             if (generatedKeys.next()) {
  23.                 id = generatedKeys.getInt(1);
  24.             }
  25.             return id;
  26.         } catch (SQLException ex) {
  27.             Logger.getLogger(Tekstikayttoliittyma.class.getName()).log(Level.SEVERE, null, ex);
  28.         }
  29.         return -1;
  30.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top