Biblioteca Java - Blame information for rev 16
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
16 | mihai | 1 | |
2 | package cfr; | ||
3 | |||
4 | import java.sql.*; | ||
5 | import java.util.ArrayList; | ||
6 | |||
7 | public class ConexiuneDb { | ||
8 | Connection con; | ||
9 | |||
10 | public ConexiuneDb() throws Exception{ | ||
11 | Class.forName("com.mysql.jdbc.Driver"); | ||
12 | con= DriverManager.getConnection("jdbc:mysql://localhost/cfr?user=root"); | ||
13 | } | ||
14 | |||
15 | ArrayList<Tren> cautaTrenuri(String statia_plecare){ | ||
16 | ArrayList<Tren> lista = new ArrayList<Tren>(); | ||
17 | try{ | ||
18 | Statement st = con.createStatement(); | ||
19 | ResultSet result = | ||
20 | st.executeQuery("SELECT * FROM merstrenuri WHERE statie_plecare='"+statia_plecare+"';"); | ||
21 | while(result.next()){ | ||
22 | int id = result.getInt(1); | ||
23 | String sp = result.getString(2); | ||
24 | String ss = result.getString(3); | ||
25 | int ora = result.getInt(4); | ||
26 | int stare = result.getInt(5); | ||
27 | Tren t = new Tren(id, sp, ss, ora, stare); | ||
28 | lista.add(t); | ||
29 | } | ||
30 | |||
31 | }catch(Exception e){ | ||
32 | e.printStackTrace(); | ||
33 | } | ||
34 | return lista; | ||
35 | |||
36 | } | ||
37 | |||
38 | ArrayList<Tren> cautaTrenuri(String statia_plecare, int ora_plecare){ | ||
39 | ArrayList<Tren> lista = new ArrayList<Tren>(); | ||
40 | try{ | ||
41 | Statement st = con.createStatement(); | ||
42 | ResultSet result = | ||
43 | st.executeQuery("SELECT * FROM merstrenuri WHERE statie_plecare='"+statia_plecare+"' AND ora_plecare="+ora_plecare+";"); | ||
44 | while(result.next()){ | ||
45 | int id = result.getInt(1); | ||
46 | String sp = result.getString(2); | ||
47 | String ss = result.getString(3); | ||
48 | int ora = result.getInt(4); | ||
49 | int stare = result.getInt(5); | ||
50 | Tren t = new Tren(id, sp, ss, ora, stare); | ||
51 | lista.add(t); | ||
52 | } | ||
53 | |||
54 | }catch(Exception e){ | ||
55 | e.printStackTrace(); | ||
56 | } | ||
57 | return lista; | ||
58 | |||
59 | } | ||
60 | |||
61 | } |