Advertisement
Guest User

Insert/Abfrage

a guest
Nov 27th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1.  Connection connection = null;
  2.             String sql = "insert into rideoffers  (creationdate, releasedate, numberofseats, vehicletype, baggagetype, ridecycle, backoutinterval, description, firststation) values (timestamp '2014-11-26 08:00', timestamp '2014-11-28 08:00', 4, 'CAR', 'MEDIUM', 'SINGLE', 1, 'Dies ist eine Testfahrt.', 1)";
  3.             try {
  4.                 connection = ConnectionPool.getInstance().getConnection();
  5.                 Statement statement = connection.createStatement();
  6.                 statement.executeQuery(sql);
  7.                 sql = "insert into stations (id, location, district, nextstation, starttime) VALUES (3, 'Passau', 'ZOB', NULL, timestamp '2014-11-28 20:00');";
  8.                 statement.executeQuery(sql);
  9.                 sql = "insert into stations (id, location, district, nextstation, starttime) VALUES (2, 'München', 'München Hbf', 3, 2014-11-28 22:00');";
  10.                 statement.executeQuery(sql);
  11.                 sql = "insert into stations (id, location, district, nextstation, starttime) VALUES (1, 'Rosenheim', 'Erlenau', 2, 2014-11-28 23:00');";
  12.                 statement.executeQuery(sql);
  13.  
  14.             } catch (SQLException e) {
  15.                 System.out.println("insert funktioniert ned");
  16.             }
  17.  
  18.             search = new Search();
  19.             search.setStart("München");
  20.             search.setDestination("Erlenau");
  21.             LocalDateTime date = LocalDateTime.of(LocalDate.of(2014, 11, 28),
  22.                     LocalTime.MIDNIGHT);
  23.             search.setDate(Utility.convertFromLocalDateTime(date));
  24.             try {
  25.                 int offerCount = RideOfferDAO.getOfferCount(search, null);
  26.                 System.out.println("OfferCount: " + offerCount);
  27.             } catch (StorageException e) {
  28.                 System.out.println("storageException");
  29.             }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. //Utitlity Klasse
  42.  
  43.   public static Date convertFromLocalDateTime(LocalDateTime date) {
  44.         Calendar calendar = Calendar.getInstance();
  45.         calendar.set(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
  46.        
  47.         return new java.util.Date(calendar.getTimeInMillis());
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement