Guest User

sql

a guest
Jun 16th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. public static List<Lot> showFlights() {
  2.         List<Lot> list = new ArrayList<>() ;
  3.         Connection connect;
  4.         Statement statement;
  5.         ResultSet resultSet;
  6.         try {
  7.             Class.forName("com.mysql.jdbc.Driver");
  8.             connect = DriverManager.getConnection("jdbc:mysql://localhost/lotnisko?user=root");
  9.             statement = connect.createStatement();
  10.             resultSet = statement.executeQuery("select * from loty where 1");
  11.  
  12.             while (resultSet.next()) {
  13.  
  14.             list.add(new Lot(Integer.parseInt(resultSet.getString(1)), resultSet.getString(2), resultSet.getString(3), resultSet.getString(4), resultSet.getString(5)));
  15.  
  16.             }
  17.  
  18.             if (resultSet != null) {
  19.                 resultSet.close();
  20.             }
  21.             if (statement != null) {
  22.                 statement.close();
  23.             }
  24.             if (connect != null) {
  25.                 connect.close();
  26.             }
  27.         } catch (Exception e) {
  28.             e.printStackTrace();
  29.         }
  30.         return list;
  31.     }
Add Comment
Please, Sign In to add comment