Explorar el Código

morning commit

Trinh Tong hace 6 años
padre
commit
a5f6db859a

+ 34
- 34
H2-Worksheet.md Ver fichero

41
 ```SQL
41
 ```SQL
42
 UPDATE people SET birthday = '1955-01-25' 
42
 UPDATE people SET birthday = '1955-01-25' 
43
 WHERE 
43
 WHERE 
44
-	last_name = 'Smith' 
44
+	lastName = 'Smith' 
45
 	AND id = 4;
45
 	AND id = 4;
46
 ```
46
 ```
47
 
47
 
48
 ```SQL
48
 ```SQL
49
-UPDATE people SET mobile = '333-3333', last_name = 'Johnson' 
50
-WHERE first_name = 'Noelle' OR first_name = 'Raj';
49
+UPDATE people SET mobile = '333-3333', lastName = 'Johnson' 
50
+WHERE firstName = 'Noelle' OR firstName = 'Raj';
51
 ```
51
 ```
52
 
52
 
53
 ## Basic Functions
53
 ## Basic Functions
69
 ```
69
 ```
70
 
70
 
71
 ```SQL
71
 ```SQL
72
-SELECT COUNT(DISTINCT last_name) FROM PEOPLE;
72
+SELECT COUNT(DISTINCT lastName) FROM PEOPLE;
73
 ```
73
 ```
74
 
74
 
75
 ```SQL
75
 ```SQL
109
 ```
109
 ```
110
 
110
 
111
 ```SQL
111
 ```SQL
112
-SELECT CONCAT(first_name, ' ', last_name) 
112
+SELECT CONCAT(firstName, ' ', lastName) 
113
 FROM people 
113
 FROM people 
114
-WHERE last_name = 'Smith'
114
+WHERE lastName = 'Smith'
115
 ```
115
 ```
116
 
116
 
117
 ```SQL
117
 ```SQL
118
-SELECT CONCAT_WS(' ',first_name, last_name, mobile) 
119
-FROM people WHERE last_name= 'Smith'
118
+SELECT CONCAT_WS(' ',firstName, lastName, mobile) 
119
+FROM people WHERE lastName= 'Smith'
120
 ```
120
 ```
121
 
121
 
122
 ```SQL
122
 ```SQL
142
 ## Compare
142
 ## Compare
143
 
143
 
144
 ```SQL
144
 ```SQL
145
-SELECT first_name, last_name, YEAR(birthday) FROM people WHERE birthday >= '1970-07-06' AND birthday<='1987-07-06';
145
+SELECT firstName, lastName, YEAR(birthday) FROM people WHERE birthday >= '1970-07-06' AND birthday<='1987-07-06';
146
 ```
146
 ```
147
 
147
 
148
 ```SQL
148
 ```SQL
149
-SELECT first_name, birthday FROM people WHERE first_name='Thomas' OR first_name='Raj' OR first_name='Sheeri';
149
+SELECT firstName, birthday FROM people WHERE firstName='Thomas' OR firstName='Raj' OR firstName='Sheeri';
150
 ```
150
 ```
151
 
151
 
152
 ```SQL
152
 ```SQL
153
-SELECT first_name, birthday FROM people WHERE first_name IN ('Noelle', 'Thomas', 'Raj');
153
+SELECT firstName, birthday FROM people WHERE firstName IN ('Noelle', 'Thomas', 'Raj');
154
 ```
154
 ```
155
 
155
 
156
 #### Wild Cards
156
 #### Wild Cards
157
 
157
 
158
 ```SQL
158
 ```SQL
159
-SELECT first_name FROM PEOPLE WHERE RIGHT(first_name,1)='e';
159
+SELECT firstName FROM PEOPLE WHERE RIGHT(firstName,1)='e';
160
 ```
160
 ```
161
 
161
 
162
 ```SQL
162
 ```SQL
163
-SELECT first_name FROM people WHERE first_name LIKE '%j'; 
163
+SELECT firstName FROM people WHERE firstName LIKE '%j'; 
164
 ```
164
 ```
165
 
165
 
166
 ```SQL
166
 ```SQL
167
-SELECT first_name FROM people WHERE first_name LIKE '%o%';
167
+SELECT firstName FROM people WHERE firstName LIKE '%o%';
168
 ```
168
 ```
169
 
169
 
170
 ```SQL
170
 ```SQL
171
-SELECT first_name FROM people WHERE first_name NOT LIKE '%o%';
171
+SELECT firstName FROM people WHERE firstName NOT LIKE '%o%';
172
 ```
172
 ```
173
 
173
 
174
 ```SQL
174
 ```SQL
176
 ```
176
 ```
177
 
177
 
178
 ```SQL
178
 ```SQL
179
-SELECT last_name, COUNT(*) FROM people GROUP BY last_name;
179
+SELECT lastName, COUNT(*) FROM people GROUP BY lastName;
180
 ```
180
 ```
181
 
181
 
182
 ```SQL
182
 ```SQL
183
-SELECT last_name, GROUP_CONCAT(mobile) FROM PEOPLE GROUP BY last_name;
183
+SELECT lastName, GROUP_CONCAT(mobile) FROM PEOPLE GROUP BY lastName;
184
 ```
184
 ```
185
 
185
 
186
 ```SQL
186
 ```SQL
187
-SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY last_name;
187
+SELECT lastName, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY lastName;
188
 ```
188
 ```
189
 
189
 
190
 ```SQL
190
 ```SQL
191
-SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY last_name  HAVING COUNT(*)>1;
191
+SELECT lastName, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people GROUP BY lastName  HAVING COUNT(*)>1;
192
 ```
192
 ```
193
 
193
 
194
 ```SQL
194
 ```SQL
195
-SELECT last_name, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people WHERE last_name != 'Cabral' GROUP BY last_name  HAVING COUNT(*)>1;
195
+SELECT lastName, GROUP_CONCAT(mobile SEPARATOR ' and ') FROM people WHERE lastName != 'Cabral' GROUP BY lastName  HAVING COUNT(*)>1;
196
 ```
196
 ```
197
 
197
 
198
 #### Sorting 
198
 #### Sorting 
199
 
199
 
200
 ```SQL
200
 ```SQL
201
-SELECT first_name, birthday FROM people ORDER BY birthday;
201
+SELECT firstName, birthday FROM people ORDER BY birthday;
202
 ```
202
 ```
203
 
203
 
204
 ```SQL
204
 ```SQL
205
-SELECT first_name, birthday FROM people ORDER BY birthday DESC;
205
+SELECT firstName, birthday FROM people ORDER BY birthday DESC;
206
 ```
206
 ```
207
 
207
 
208
 ```SQL
208
 ```SQL
209
-SELECT first_name, last_name FROM people ORDER BY last_name, first_name;
209
+SELECT firstName, lastName FROM people ORDER BY lastName, firstName;
210
 ```
210
 ```
211
 
211
 
212
 ```SQL
212
 ```SQL
213
-SELECT first_name, birthday FROM people ORDER BY birthday DESC LIMIT 3;
213
+SELECT firstName, birthday FROM people ORDER BY birthday DESC LIMIT 3;
214
 ```
214
 ```
215
 
215
 
216
 ```SQL
216
 ```SQL
217
-SELECT first_name, MONTHNAME(birthday) as mon, birthday FROM people ORDER BY MONTH(birthday);
217
+SELECT firstName, MONTHNAME(birthday) as mon, birthday FROM people ORDER BY MONTH(birthday);
218
 ```
218
 ```
219
 
219
 
220
 ```SQL
220
 ```SQL
221
-SELECT last_name, COUNT(*) FROM  people GROUP BY last_name;
221
+SELECT lastName, COUNT(*) FROM  people GROUP BY lastName;
222
 ```
222
 ```
223
 
223
 
224
 ```SQL
224
 ```SQL
225
-SELECT last_name, COUNT(*) FROM  people GROUP BY last_name ORDER BY NULL;
225
+SELECT lastName, COUNT(*) FROM  people GROUP BY lastName ORDER BY NULL;
226
 ```
226
 ```
227
 
227
 
228
 ## Inserting and Replacing Records
228
 ## Inserting and Replacing Records
229
 
229
 
230
 ```SQL
230
 ```SQL
231
-INSERT INTO people (first_name, last_name, birthday, home_id)
231
+INSERT INTO people (firstName, lastName, birthday, home_id)
232
 	VALUES
232
 	VALUES
233
 	('John', 'Smith', '1998-04-07', 4),
233
 	('John', 'Smith', '1998-04-07', 4),
234
 	('Maya', 'Wasserman' , NULL, 4),
234
 	('Maya', 'Wasserman' , NULL, 4),
238
 #### Replace
238
 #### Replace
239
 
239
 
240
 ```SQL
240
 ```SQL
241
-DELETE FROM people WHERE first_name='Maya';
241
+DELETE FROM people WHERE firstName='Maya';
242
 ```
242
 ```
243
 
243
 
244
 ```SQL
244
 ```SQL
246
 ```
246
 ```
247
 
247
 
248
 ```SQL
248
 ```SQL
249
-MERGE INTO people (first_name, last_name, birthday, home_id)
249
+MERGE INTO people (firstName, lastName, birthday, home_id)
250
 	VALUES
250
 	VALUES
251
 	('John', 'Sharma', '1998-04-07', 1),
251
 	('John', 'Sharma', '1998-04-07', 1),
252
 	('Paul', 'Sharma', '1996-05-27', 4),
252
 	('Paul', 'Sharma', '1996-05-27', 4),
257
 ## JOIN
257
 ## JOIN
258
 
258
 
259
 ```SQL
259
 ```SQL
260
-INSERT INTO people (first_name, last_name, birthday)
260
+INSERT INTO people (firstName, lastName, birthday)
261
 	VALUES ('Eli', 'Kramer', '1984-01-15');
261
 	VALUES ('Eli', 'Kramer', '1984-01-15');
262
 ```
262
 ```
263
 	
263
 	
271
 ```
271
 ```
272
 
272
 
273
 ```SQL
273
 ```SQL
274
-SELECT p.first_name, h.address 
274
+SELECT p.firstName, h.address 
275
 FROM PEOPLE p
275
 FROM PEOPLE p
276
 INNER JOIN HOME h  on (p.HOME_ID = h.ID)
276
 INNER JOIN HOME h  on (p.HOME_ID = h.ID)
277
 ```
277
 ```
278
 
278
 
279
 ```SQL
279
 ```SQL
280
-SELECT first_name, last_name
280
+SELECT firstName, lastName
281
 FROM PEOPLE p
281
 FROM PEOPLE p
282
 INNER JOIN HOME h  on (p.HOME_ID = h.HOME_ID)
282
 INNER JOIN HOME h  on (p.HOME_ID = h.HOME_ID)
283
 WHERE p.HOME_ID = 1
283
 WHERE p.HOME_ID = 1
287
 SELECT p.*, h.address, h.homenumber
287
 SELECT p.*, h.address, h.homenumber
288
 FROM PEOPLE p
288
 FROM PEOPLE p
289
 INNER JOIN HOME h  on (p.HOME_ID = h.HOME_ID)
289
 INNER JOIN HOME h  on (p.HOME_ID = h.HOME_ID)
290
-WHERE p.first_name  LIKE '%e%'
290
+WHERE p.firstName  LIKE '%e%'
291
 ```
291
 ```
292
 
292
 
293
 ##### Exercise:
293
 ##### Exercise:

+ 0
- 2
data-h2.sql Ver fichero

11
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Thomas', '395-6181', '1987-07-06', 1);
11
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Thomas', '395-6181', '1987-07-06', 1);
12
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
12
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
13
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);
13
 INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);
14
-
15
-

+ 64
- 0
src/main/java/io/zipcoder/persistenceapp/PersistenceStarterApplication.java Ver fichero

1
 package io.zipcoder.persistenceapp;
1
 package io.zipcoder.persistenceapp;
2
 
2
 
3
+import io.zipcoder.persistenceapp.service.PersonService;
3
 import org.h2.server.web.WebServlet;
4
 import org.h2.server.web.WebServlet;
5
+import org.springframework.beans.factory.annotation.Autowired;
4
 import org.springframework.boot.SpringApplication;
6
 import org.springframework.boot.SpringApplication;
5
 import org.springframework.boot.autoconfigure.SpringBootApplication;
7
 import org.springframework.boot.autoconfigure.SpringBootApplication;
6
 import org.springframework.boot.web.servlet.ServletRegistrationBean;
8
 import org.springframework.boot.web.servlet.ServletRegistrationBean;
7
 import org.springframework.context.annotation.Bean;
9
 import org.springframework.context.annotation.Bean;
8
 
10
 
11
+import java.sql.*;
12
+
9
 @SpringBootApplication
13
 @SpringBootApplication
10
 public class PersistenceStarterApplication {
14
 public class PersistenceStarterApplication {
11
 
15
 
16
+	@Autowired
17
+	static PersonService personService;
18
+
19
+	// JDBC driver name and database URL
20
+	static final String JDBC_DRIVER = "org.h2.Driver";
21
+	static final String DB_URL = "jdbc:h2:mem:testdb";
22
+
23
+	//  Database credentials
24
+	static final String USER = "sa";
25
+	static final String PASS = "";
26
+
12
 	public static void main(String[] args) {
27
 	public static void main(String[] args) {
13
 		SpringApplication.run(PersistenceStarterApplication.class, args);
28
 		SpringApplication.run(PersistenceStarterApplication.class, args);
29
+
30
+		Connection conn = null;
31
+		Statement stmt = null;
32
+		try{
33
+			// STEP 1: Register JDBC driver
34
+			Class.forName(JDBC_DRIVER);
35
+
36
+			// STEP 2: Open a connection
37
+			System.out.println("Connecting to a selected database...");
38
+			conn = DriverManager.getConnection(DB_URL,USER,PASS);
39
+			System.out.println("Connected database successfully...");
40
+
41
+			// STEP 3: Execute a query
42
+			stmt = conn.createStatement();
43
+			String sql = "SELECT * FROM PERSON";
44
+			ResultSet rs = stmt.executeQuery(sql);
45
+			System.out.println("query result: ");
46
+
47
+			while(rs.next()) {
48
+				System.out.println("ID: " + rs.getInt(1));
49
+				System.out.println("First name: " + rs.getString(2));
50
+				System.out.println("Last name: " + rs.getString(3));
51
+				System.out.println("Mobile phone: " + rs.getString(4));
52
+				System.out.println("Birthday date: " + rs.getString(5));
53
+				System.out.println("Home ID: " + rs.getInt(6));
54
+			}
55
+
56
+			// STEP 4: Clean-up environment
57
+			stmt.close();
58
+			conn.close();
59
+		} catch(SQLException se) {
60
+			// Handle errors for JDBC
61
+			se.printStackTrace();
62
+		} catch(Exception e) {
63
+			// Handle errors for Class.forName
64
+			e.printStackTrace();
65
+		} finally {
66
+			// finally block used to close resources
67
+			try {
68
+				if(stmt!=null) stmt.close();
69
+			} catch(SQLException se2) {
70
+			} // nothing we can do
71
+			try {
72
+				if(conn!=null) conn.close();
73
+			} catch(SQLException se) {
74
+				se.printStackTrace();
75
+			} // end finally try
76
+		} // end try
77
+		System.out.println("Goodbye!");
14
 	}
78
 	}
15
 
79
 
16
 	@Bean
80
 	@Bean

+ 22
- 0
src/main/java/io/zipcoder/persistenceapp/controller/PersonController.java Ver fichero

1
+package io.zipcoder.persistenceapp.controller;
2
+
3
+import io.zipcoder.persistenceapp.model.Person;
4
+import io.zipcoder.persistenceapp.service.PersonService;
5
+import org.springframework.beans.factory.annotation.Autowired;
6
+import org.springframework.http.HttpStatus;
7
+import org.springframework.http.ResponseEntity;
8
+import org.springframework.web.bind.annotation.RequestMapping;
9
+import org.springframework.web.bind.annotation.RequestMethod;
10
+import org.springframework.web.bind.annotation.RestController;
11
+
12
+@RestController
13
+public class PersonController {
14
+    @Autowired
15
+    PersonService personService;
16
+
17
+    @RequestMapping(value="/person", method= RequestMethod.GET)
18
+    public ResponseEntity<Iterable<Person>> getPeople() {
19
+        Iterable<Person> people = personService.getAllPeople();
20
+        return new ResponseEntity<>(people, HttpStatus.OK);
21
+    }
22
+}

+ 24
- 20
src/main/java/io/zipcoder/persistenceapp/model/Person.java Ver fichero

3
 import java.util.Date;
3
 import java.util.Date;
4
 
4
 
5
 public class Person {
5
 public class Person {
6
-
7
     private Long id;
6
     private Long id;
8
-    private String first_name, last_name, mobile;
7
+    private String firstName, lastName, mobile;
9
     private Date birthday;
8
     private Date birthday;
10
-    private Integer home_ID;
9
+    private Integer homeId;
11
 
10
 
12
-    public Person() {
13
-    }
11
+    public Person() {}
14
 
12
 
15
-    public Person(Long id, String first_name, String last_name) {
13
+    public Person(Long id, String firstName, String lastName) {
16
         this.id = id;
14
         this.id = id;
17
-        this.first_name = first_name;
18
-        this.last_name = last_name;
15
+        this.firstName = firstName;
16
+        this.lastName = lastName;
19
     }
17
     }
20
 
18
 
21
     public Long getId() {
19
     public Long getId() {
26
         this.id = id;
24
         this.id = id;
27
     }
25
     }
28
 
26
 
29
-    public String getFirst_name() {
30
-        return first_name;
27
+    public String getFirstName() {
28
+        return firstName;
31
     }
29
     }
32
 
30
 
33
-    public void setFirst_name(String first_name) {
34
-        this.first_name = first_name;
31
+    public void setFirstName(String firstName) {
32
+        this.firstName = firstName;
35
     }
33
     }
36
 
34
 
37
-    public String getLast_name() {
38
-        return last_name;
35
+    public String getLastName() {
36
+        return lastName;
39
     }
37
     }
40
 
38
 
41
-    public void setLast_name(String last_name) {
42
-        this.last_name = last_name;
39
+    public void setLastName(String lastName) {
40
+        this.lastName = lastName;
43
     }
41
     }
44
 
42
 
45
     public String getMobile() {
43
     public String getMobile() {
58
         this.birthday = birthday;
56
         this.birthday = birthday;
59
     }
57
     }
60
 
58
 
61
-    public Integer getHome_ID() {
62
-        return home_ID;
59
+    public Integer getHomeId() {
60
+        return homeId;
61
+    }
62
+
63
+    public void setHomeId(Integer homeId) {
64
+        this.homeId = homeId;
63
     }
65
     }
64
 
66
 
65
-    public void setHome_ID(Integer home_ID) {
66
-        this.home_ID = home_ID;
67
+    @Override
68
+    public java.lang.String toString() {
69
+        return String.format("Person [id=%s, firstName=%s, lastName=%s, mobile=%s, birthday=%s, homeId=%s]", id,
70
+                firstName, lastName, mobile, birthday, homeId);
67
     }
71
     }
68
 }
72
 }

+ 49
- 3
src/main/java/io/zipcoder/persistenceapp/service/PersonService.java Ver fichero

2
 
2
 
3
 import io.zipcoder.persistenceapp.model.Person;
3
 import io.zipcoder.persistenceapp.model.Person;
4
 import org.springframework.beans.factory.annotation.Autowired;
4
 import org.springframework.beans.factory.annotation.Autowired;
5
+import org.springframework.jdbc.core.BeanPropertyRowMapper;
5
 import org.springframework.jdbc.core.JdbcTemplate;
6
 import org.springframework.jdbc.core.JdbcTemplate;
7
+import org.springframework.jdbc.core.RowMapper;
6
 import org.springframework.stereotype.Service;
8
 import org.springframework.stereotype.Service;
7
 
9
 
8
 import java.sql.JDBCType;
10
 import java.sql.JDBCType;
11
+import java.sql.ResultSet;
12
+import java.sql.SQLException;
13
+import java.util.Arrays;
14
+import java.util.Iterator;
15
+import java.util.List;
9
 
16
 
10
 /*
17
 /*
11
 Service speaks to the repo/jdbc template, controller speaks to service to get stuff
18
 Service speaks to the repo/jdbc template, controller speaks to service to get stuff
19
     @Autowired
26
     @Autowired
20
     JdbcTemplate jdbcTemplate;
27
     JdbcTemplate jdbcTemplate;
21
 
28
 
22
-    public PersonService() {
29
+    public PersonService() {}
30
+
31
+    class PersonRowMapper implements RowMapper<Person> {
32
+        @Override
33
+        public Person mapRow(ResultSet rs, int rowNum) throws SQLException {
34
+            Person person = new Person();
35
+            person.setId(rs.getLong("id"));
36
+            person.setFirstName(rs.getString("first_name"));
37
+            person.setLastName(rs.getString("last_name"));
38
+            person.setMobile(rs.getString("mobile"));
39
+            person.setBirthday(rs.getDate("birthday"));
40
+            person.setHomeId(rs.getInt("home_id"));
41
+            return person;
42
+        }
23
     }
43
     }
24
 
44
 
25
     public void add(Person p) {
45
     public void add(Person p) {
26
-        Object[] info = {p.getFirst_name(), p.getLast_name(), p.getMobile(), p.getBirthday(), p.getHome_ID()};
46
+        Object[] info = {p.getFirstName(), p.getLastName(), p.getMobile(), p.getBirthday(), p.getHomeId()};
27
         jdbcTemplate.update(
47
         jdbcTemplate.update(
28
                 "INSERT INTO person (first_name, last_name, mobile, birthday, home_ID)" +
48
                 "INSERT INTO person (first_name, last_name, mobile, birthday, home_ID)" +
29
                         "VALUES (?, ?, ?, ?, ?)", info, types);
49
                         "VALUES (?, ?, ?, ?, ?)", info, types);
30
     }
50
     }
31
 
51
 
32
     public void update(Person p) {
52
     public void update(Person p) {
33
-        Object[] info = {p.getFirst_name(), p.getLast_name(), p.getMobile(), p.getBirthday(), p.getHome_ID()};
53
+        Object[] info = {p.getFirstName(), p.getLastName(), p.getMobile(), p.getBirthday(), p.getHomeId()};
34
         jdbcTemplate.update(
54
         jdbcTemplate.update(
35
                 "UPDATE person set first_name = ?, last_name ?, mobile = ?, birthday = ?, home_ID = ?" +
55
                 "UPDATE person set first_name = ?, last_name ?, mobile = ?, birthday = ?, home_ID = ?" +
36
                         "VALUES (?, ?, ?, ?, ?)", info, types);
56
                         "VALUES (?, ?, ?, ?, ?)", info, types);
40
         jdbcTemplate.update("DELETE FROM person WHERE id = ?", id);
60
         jdbcTemplate.update("DELETE FROM person WHERE id = ?", id);
41
     }
61
     }
42
 
62
 
63
+    public void removePeople(Iterable<Person> p) {
64
+        p.forEach(person -> remove(person.getId()));
65
+    }
66
+
67
+    public Person findPersonById(Integer id) {
68
+        return jdbcTemplate.queryForObject("SELECT * FROM PERSON WHERE ID=?", new Object[] {id},
69
+                new BeanPropertyRowMapper<>(Person.class));
70
+    }
71
+
72
+    public List<Person> getAllPeople() {
73
+        return jdbcTemplate.query("SELECT * FROM PERSON", new PersonRowMapper());
74
+    }
43
 
75
 
76
+    public List<Person> findPeopleByMobile(String mobile) {
77
+        return jdbcTemplate.query("SELECT * FROM PERSON WHERE MOBILE=?", new Object[] {mobile},
78
+                new PersonRowMapper());
79
+    }
80
+
81
+    public List<Person> findPeopleByLastName(String lastName) {
82
+        return jdbcTemplate.query("SELECT * FROM PERSON WHERE LAST_NAME=?", new Object[] {lastName},
83
+                new PersonRowMapper());
84
+    }
85
+
86
+    public List<Person> generateSurnameMap(String lastName) {
87
+        return jdbcTemplate.query("SELECT * FROM PERSON WHERE LAST_NAME=?", new Object[] {lastName},
88
+                new PersonRowMapper());
89
+    }
44
 }
90
 }

+ 39
- 0
src/main/resources/data.sql Ver fichero

1
+INSERT into movies (title, runtime, genre, imdb_score, rating)
2
+VALUES ('Howard the Duck', 110, 'Sci-Fi', 4.6, 'PG');
3
+
4
+INSERT into movies (title, runtime, genre, imdb_score, rating)
5
+VALUES ('Lavalantula', 83, 'Horror', 4.7, 'TV-14');
6
+
7
+INSERT into movies (title, runtime, genre, imdb_score, rating)
8
+VALUES ('Starship Troopers', 129, 'Sci-Fi', 7.2, 'PG-13');
9
+
10
+INSERT into movies (title, runtime, genre, imdb_score, rating)
11
+VALUES ('Waltz With Bashir', 90, 'Documentary', 8.0, 'R');
12
+
13
+INSERT into movies (title, runtime, genre, imdb_score, rating)
14
+VALUES ('Spaceballs', 96, 'Comedy', 7.1, 'PG');
15
+
16
+INSERT into movies (title, runtime, genre, imdb_score, rating)
17
+VALUES ('Monsters Inc.', 92, 'Animation', 8.1, 'G');
18
+
19
+INSERT into movies (title, runtime, genre, imdb_score, rating)
20
+VALUES ('Finding Nemo', 101, 'Animation', 8.1, 'G');
21
+
22
+INSERT into movies (title, runtime, genre, imdb_score, rating)
23
+VALUES ('Just Go With It', 117, 'Comedy', 6.4, 'PG-13');
24
+
25
+INSERT into movies (title, runtime, genre, imdb_score, rating)
26
+VALUES ('Dodgeball', 117, 'Comedy', 6.7, 'PG-13');
27
+
28
+INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('36 E. Bayberry Rd.Savannah, GA 31404', '565-6895');
29
+INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('11 Essex Dr.Farmingdale, NY 11735', '454-4544');
30
+INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('920 Arlington Street Clifton, NJ 07011', '985-4515');
31
+INSERT INTO HOME (ADDRESS, HOMENUMBER) VALUES ('234 High Street, PA 19159 ', '267-3940');
32
+
33
+
34
+INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID ) VALUES ('Carbral', 'Sheeri', '230-4233', '1970-02-23', 2);
35
+INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID) VALUES ( 'Sharam', 'Raj', '186-5223', '1980-08-31', 3);
36
+INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Durand', 'Noelle', '395-6161', '1960-07-06', 1);
37
+INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Thomas', '395-6181', '1987-07-06', 1);
38
+INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Smith', 'Jane', '393-6181', '1987-12-06', 3);
39
+INSERT INTO PERSON ( LAST_NAME, FIRST_NAME, MOBILE, BIRTHDAY, HOME_ID)VALUES ('Brown', 'Doug', '466-6241', '1954-12-07', 3);