-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseConnection.java
More file actions
704 lines (622 loc) · 26.6 KB
/
Copy pathDatabaseConnection.java
File metadata and controls
704 lines (622 loc) · 26.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
package com.mycompany.csc365p1;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date;
public class DatabaseConnection {
Connection connection;
DatabaseConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(
"jdbc:mysql://ambari-node5.csc.calpoly.edu:3306/gr0up0", "gr0up0", "test123");
System.out.println("Connected to DB");
} catch (Exception e) {
e.printStackTrace();
}
}
public Connection getConnection() {
return connection;
}
public Artist selectArtistByName(String name) {
try {
String selectString = "SELECT * FROM Artists WHERE artistName = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, name);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
return new Artist(name);
} else {
System.out.println("No artist with name" + name + "found");
}
selectStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public ArrayList<Song> findSongs(String songTitle, String artist, String album, String duration, String genre, String era) throws SQLException, NumberFormatException {
ArrayList<Song> songs = new ArrayList<>();
ArrayList<String> selectStringParts = new ArrayList<>();
ArrayList<Object> params = new ArrayList<>();
if (songTitle != null) {
selectStringParts.add("songTitle = ?");
params.add(songTitle);
}
if (artist != null) {
selectStringParts.add("artist = ?");
params.add(artist);
}
if (album != null) {
selectStringParts.add("album = ?");
params.add(album);
}
if (duration != null) {
selectStringParts.add("duration = ?");
params.add(Integer.parseInt(duration));
}
if (genre != null) {
selectStringParts.add("genre = ?");
params.add(genre);
}
if (era != null) {
selectStringParts.add("era = ?");
params.add(era);
}
if (params.isEmpty()) return songs;
String selectString = String.join(" AND ", selectStringParts);
selectString += ";";
selectString = "SELECT * FROM Songs WHERE " + selectString;
PreparedStatement selectStmt = connection.prepareStatement(selectString);
for (int i = 0; i < params.size(); i++) {
selectStmt.setObject(i + 1, params.get(i));
}
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
String foundTitle = rs.getString("songTitle");
String foundArtist = rs.getString("artist");
String foundAlbum = rs.getString("album");
int foundDuration = rs.getInt("duration");
String foundGenre = rs.getString("genre");
String foundEra = rs.getString("era");
songs.add(new Song(foundTitle, foundArtist, foundAlbum, foundDuration, foundGenre, foundEra));
}
return songs;
}
public boolean deleteSong(Song song) {
try {
String deleteString = "DELETE FROM Songs WHERE songTitle = ? AND artist = ?";
PreparedStatement deleteStmt = connection.prepareStatement(deleteString);
deleteStmt.setString(1, song.getSongTitle());
deleteStmt.setString(2, song.getArtist());
deleteStmt.executeUpdate();
return true;
} catch (SQLException e) {
System.out.println("Error deleting song");
e.printStackTrace();
}
return false;
}
public void deletePlaylist(String playlistName) throws SQLException {
String deleteString = "DELETE FROM Playlists WHERE playlistName = ?";
PreparedStatement deleteStmt = connection.prepareStatement(deleteString);
deleteStmt.setString(1, playlistName);
deleteStmt.executeUpdate();
}
public Song findSong(String songTitle, String artist) {
try {
String selectString = "SELECT * FROM Songs WHERE songTitle = ? AND artist = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, songTitle);
selectStmt.setString(2, artist);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
String album = rs.getString("album");
int duration = rs.getInt("duration");
String genre = rs.getString("genre");
String era = rs.getString("era");
return new Song(songTitle, artist, album, duration, genre, era);
} else {
System.out.println("No song found for: " + songTitle + "and " + artist + " !");
}
} catch (SQLException e) {
System.out.println("Error selecting songs by title");
e.printStackTrace();
}
return null;
}
public ArrayList<Song> selectSongsByTitle(String title) {
ArrayList<Song> songs = new ArrayList<>();
try {
String selectString = "SELECT * FROM Songs WHERE songTitle = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, title);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
String artist = rs.getString("artist");
String album = rs.getString("album");
int duration = rs.getInt("duration");
String genre = rs.getString("genre");
String era = rs.getString("era");
songs.add(new Song(title, artist, album, duration, genre, era));
} else {
System.out.println("No song found for: " + title + "!");
}
selectStmt.close();
} catch (SQLException e) {
System.out.println("Error selecting songs by title");
e.printStackTrace();
}
return songs;
}
public ArrayList<Song> selectSongsByArtistAndAlbum(String artist, String album) {
ArrayList<Song> songs = new ArrayList<>();
try {
String selectString = "SELECT * FROM Songs WHERE artist = ? AND album = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, artist);
selectStmt.setString(2, album);
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
String songTitle = rs.getString("songTitle");
int duration = rs.getInt("duration");
String genre = rs.getString("genre");
String era = rs.getString("era");
songs.add(new Song(songTitle, artist, album, duration, genre, era));
}
selectStmt.close();
} catch (SQLException e) {
System.out.println("Error selecting song by title");
e.printStackTrace();
}
return songs;
}
public ArrayList<Song> selectSongsByArtist(String artist) {
ArrayList<Song> songs = new ArrayList<>();
try {
String selectString = "SELECT * FROM Songs WHERE artist = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, artist);
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
String songTitle = rs.getString("songTitle");
String album = rs.getString("album");
int duration = rs.getInt("duration");
String genre = rs.getString("genre");
String era = rs.getString("era");
songs.add(new Song(songTitle, artist, album, duration, genre, era));
}
selectStmt.close();
} catch (SQLException e) {
System.out.println("Error selecting song by title");
e.printStackTrace();
}
return songs;
}
public ArrayList<Song> selectSongsByGenre(String genre) {
ArrayList<Song> songs = new ArrayList<>();
try {
String selectString = "SELECT * FROM Songs WHERE genre = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, genre);
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
String songTitle = rs.getString("songTitle");
String album = rs.getString("album");
int duration = rs.getInt("duration");
String artist = rs.getString("artist");
String era = rs.getString("era");
songs.add(new Song(songTitle, artist, album, duration, genre, era));
}
selectStmt.close();
} catch (SQLException e) {
System.out.println("Error selecting song by genre");
e.printStackTrace();
}
return songs;
}
public ArrayList<String> selectAllAlbumsByArtist(String artist) {
ArrayList<String> albums = new ArrayList<>();
try {
String selectString = "SELECT * FROM Albums WHERE artist = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, artist);
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
String albumName = rs.getString("albumName");
albums.add(albumName);
}
selectStmt.close();
} catch (SQLException e) {
System.out.println("Error selecting album by artist " + artist);
e.printStackTrace();
}
return albums;
}
public ArrayList<String> selectAllArtistsByAlbum(String albumName) {
ArrayList<String> artists = new ArrayList<>();
try {
String selectString = "SELECT * FROM Albums WHERE albumName = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, albumName);
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
String artist = rs.getString("artist");
artists.add(artist);
}
selectStmt.close();
} catch (SQLException e) {
System.out.println("Error selecting album by album " + albumName);
e.printStackTrace();
}
return artists;
}
public ResultSet selectAllSongs() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM Songs");
return selectStmt.executeQuery();
}
public ResultSet selectAllPlaylistSongs() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM PlaylistSongs ORDER BY playlist asc;");
return selectStmt.executeQuery();
}
public ResultSet selectAllPlaylists() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM Playlists;");
return selectStmt.executeQuery();
}
public ResultSet selectAllAlbums() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM Albums;");
return selectStmt.executeQuery();
}
public ResultSet selectAllArtists() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM Artists");
return selectStmt.executeQuery();
}
public ResultSet selectAllGenres() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM Genres");
return selectStmt.executeQuery();
}
public ResultSet selectAllEras() throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT * FROM Era");
return selectStmt.executeQuery();
}
public ResultSet selectAllFromGenre(String genreName) throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT songTitle FROM Songs WHERE genre = ?");
selectStmt.setString(1, genreName);
return selectStmt.executeQuery();
}
public ResultSet selectAllFromAlbum(String albumName) throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT songTitle FROM Songs WHERE album = ?");
selectStmt.setString(1, albumName);
return selectStmt.executeQuery();
}
//i hate this one
public ResultSet selectAllByDuration(int duration) throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT songTitle FROM Songs WHERE duration = ?");
selectStmt.setInt(1, duration);
return selectStmt.executeQuery();
}
public ResultSet selectAllByArtist(String name) throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT songTitle FROM Songs WHERE artist = ?");
selectStmt.setString(1, name);
return selectStmt.executeQuery();
}
public ResultSet selectAllFromPlaylist(String playlistName) throws SQLException {
PreparedStatement selectStmt = connection.prepareStatement("SELECT song FROM PlaylistSongs WHERE playlist = ?");
selectStmt.setString(1, playlistName);
return selectStmt.executeQuery();
}
//RETURNS ARTIST_ID
public String selectPlaylistByName(String name) {
try {
String selectString = "SELECT * FROM Playlists WHERE playlistName = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, name);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
return name;
} else {
System.out.println("No playlist id found for: " + name + "!");
}
selectStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public Album selectAlbumByName(String name) {
try {
String selectString = "SELECT artist FROM Albums WHERE albumName = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, name);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
String artist = rs.getString("artist");
ArrayList<Song> tracklist = getTracklistFromPlaylist(name);
return new Album(name, artist, tracklist);
} else {
System.out.println("No playlist id found for: " + name + "!");
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
//JAMES
public void updateSong(Song oldSong, Song newSong) throws SQLException {
if (!ensureSongIntegrityConstraints(newSong.getArtist(), newSong.getAlbum(), newSong.getGenre(), newSong.getEra())) {
System.out.println("Insert song integrity constraints not met when updating song");
return;
}
PreparedStatement selectStmt = connection.prepareStatement("UPDATE Songs SET songTitle = ?, artist = ?, album = ?, duration = ?, genre = ?, era = ? WHERE songTitle = ? and artist = ?;");
selectStmt.setString(1, newSong.getSongTitle());
selectStmt.setString(2, newSong.getArtist());
selectStmt.setString(3, newSong.getAlbum());
selectStmt.setInt(4, newSong.getDuration());
selectStmt.setString(5, newSong.getGenre());
selectStmt.setString(6, newSong.getEra());
selectStmt.setString(7, oldSong.getSongTitle());
selectStmt.setString(8, oldSong.getArtist());
selectStmt.executeUpdate();
selectStmt.close();
}
public void updateArtist(Artist oldArtist, Artist newArtist) throws SQLException {
Artist artist = selectArtistByName(oldArtist.getArtistName());
ensureArtist(newArtist.getArtistName());
PreparedStatement selectStmt = connection.prepareStatement("UPDATE Artists SET artist_name = ? WHERE artist_name = ?");
selectStmt.setString(1, newArtist.getArtistName());
selectStmt.setString(2, artist.getArtistName());
selectStmt.executeQuery();
selectStmt.close();
}
public void updateAlbum(Album oldAlbum, Album newAlbum) throws SQLException {
Album album = selectAlbumByName(oldAlbum.getAlbumName());
ensureArtist(newAlbum.getArtist());
ensureAlbum(newAlbum.getAlbumName(), newAlbum.getArtist());
PreparedStatement selectStmt = connection.prepareStatement("UPDATE Albums SET album_name = ?, artist = ? WHERE album_name = ? and artist = ?");
selectStmt.setString(1, newAlbum.getAlbumName());
selectStmt.setString(2, newAlbum.getArtist());
selectStmt.setString(3, album.getAlbumName());
selectStmt.setString(4, album.getArtist());
selectStmt.executeQuery();
selectStmt.close();
}
public ArrayList<String> getPlaylistNames() {
ArrayList<String> playlistNames = new ArrayList<>();
try {
ResultSet rs = this.selectAllPlaylists();
while (rs.next()) {
playlistNames.add(rs.getString("playlistName"));
}
} catch (SQLException e) {
System.out.println("Select all playlists error");
}
return playlistNames;
}
public ArrayList<String> getGenreNames() {
ArrayList<String> genreNames = new ArrayList<>();
try {
ResultSet rs = this.selectAllGenres();
while (rs.next()) {
genreNames.add(rs.getString("genreName"));
}
} catch (SQLException e) {
System.out.println("Select genre names error");
}
return genreNames;
}
public ArrayList<String> getArtistNames() {
ArrayList<String> artistNames = new ArrayList<>();
try {
ResultSet rs = this.selectAllArtists();
while (rs.next()) {
artistNames.add(rs.getString("artistName"));
}
} catch (SQLException e) {
System.out.println("Select all artist names error");
}
return artistNames;
}
public ArrayList<String> getAlbumNames() {
ArrayList<String> albumNames = new ArrayList<>();
try {
ResultSet rs = this.selectAllAlbums();
while (rs.next()) {
albumNames.add(rs.getString("albumName"));
}
} catch (SQLException e) {
System.out.println("Select all album names error");
}
return albumNames;
}
public ArrayList<Song> getTracklistFromPlaylist(String playlist) {
try {
ArrayList<Song> tracklist = new ArrayList();
String selectString = "SELECT * FROM PlaylistSongs WHERE playlist = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, playlist);
ResultSet rs = selectStmt.executeQuery();
while (rs.next()) {
Song songToAdd = findSong(rs.getString("song"), rs.getString("artist"));
tracklist.add(songToAdd);
}
selectStmt.close();
return tracklist;
} catch (SQLException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
public ArrayList<Song> getTracklistFromAlbum(String name) {
try {
ArrayList<Song> tracklist = new ArrayList();
String selectString = "SELECT * FROM Songs WHERE album = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, name);
ResultSet rs = selectStmt.executeQuery();
if (!rs.next()) {
System.out.println("No playlist found for: " + name + "!");
}
while (rs.next()) {
Song songToAdd = findSong(rs.getString("song"), rs.getString("artist"));
tracklist.add(songToAdd);
}
return tracklist;
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public String selectGenreByName(String name) {
try {
String selectString = "SELECT * FROM Genres WHERE genreName = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, name);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
System.out.println("Found genre with name: " + name);
return name;
} else {
System.out.println("No genre with name " + name + " found");
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public String selectEraByName(String era) {
try {
String selectString = "SELECT * FROM Eras WHERE era = ?";
PreparedStatement selectStmt = connection.prepareStatement(selectString);
selectStmt.setString(1, era);
ResultSet rs = selectStmt.executeQuery();
if (rs.next()) {
System.out.println("Found era: " + era);
return era;
} else {
System.out.println("No era called " + era + " found");
}
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
public void insertSong(Song song) throws SQLException {
if (!ensureSongIntegrityConstraints(song.getArtist(), song.getAlbum(), song.getGenre(), song.getEra())) {
System.out.println("Insert song integrity constraints not met");
return;
}
String insertString = "INSERT INTO Songs (songTitle, artist, album, duration, genre, era) VALUES (?,?,?,?,?,?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
insertStmt.setString(1, song.getSongTitle());
insertStmt.setString(2, song.getArtist());
insertStmt.setString(3, song.getAlbum());
insertStmt.setInt(4, song.getDuration());
insertStmt.setString(5, song.getGenre());
insertStmt.setString(6, song.getEra());
insertStmt.executeUpdate();
insertStmt.close();
}
public boolean ensureSongIntegrityConstraints(String artist, String album, String genre, String era) {
try {
ensureArtist(artist);
ensureAlbum(album, artist);
ensureGenre(genre);
ensureEra(era);
return true;
} catch (SQLException e) {
return false;
}
}
public void insertArtist(String name) throws SQLException {
String insertString = "INSERT INTO Artists (artistName) VALUES (?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
insertStmt.setString(1, name);
insertStmt.executeUpdate();
insertStmt.close();
}
public void insertGenre(String genre) {
try {
String insertString = "INSERT INTO Genres (genreName) VALUES (?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
insertStmt.setString(1, genre);
insertStmt.executeUpdate();
insertStmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
public void insertEra(String era) {
try {
String insertString = "INSERT INTO Eras (era) VALUES (?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
insertStmt.setString(1, era);
insertStmt.executeUpdate();
insertStmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
public void insertAlbum(String name, String artistName) {
try {
String insertString = "INSERT INTO Albums (albumName, artist) VALUES (?, ?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
insertStmt.setString(1, name);
insertStmt.setString(2, artistName);
insertStmt.executeUpdate();
insertStmt.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
public void insertPlaylist(String playlistName) throws SQLException {
String insertString = "INSERT INTO Playlists (playlistName, dateCreated) VALUES (?, ?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
insertStmt.setString(1, playlistName);
Date currentDate = new Date();
insertStmt.setDate(2, new java.sql.Date(currentDate.getTime()));
insertStmt.executeUpdate();
insertStmt.close();
}
public void addSongToPlaylist(Song song, String playlistName) throws SQLException {
String insertString = "INSERT INTO PlaylistSongs (playlist, song, artist) VALUES (?, ?, ?)";
PreparedStatement insertStmt = connection.prepareStatement(insertString);
checkPlaylist(playlistName);
insertStmt.setString(1, playlistName);
insertStmt.setString(2, song.getSongTitle());
insertStmt.setString(3, song.getArtist());
insertStmt.executeUpdate();
insertStmt.close();
}
public void ensureArtist(String artist) throws SQLException {
boolean existingArtist = App.dbConn.selectArtistByName(artist) != null;
if (!existingArtist){
App.dbConn.insertArtist(artist);
}
}
public void ensureGenre(String genre) throws SQLException {
boolean existingGenre = App.dbConn.selectGenreByName(genre) != null;
if (!existingGenre) {
App.dbConn.insertGenre(genre);
}
}
public void ensureEra(String era) throws SQLException {
boolean existingEra = App.dbConn.selectEraByName(era) != null;
if (!existingEra) {
App.dbConn.insertEra(era);
}
}
public void ensureAlbum(String album, String artist) throws SQLException {
boolean existingAlbum = App.dbConn.selectAlbumByName(album) != null;
if (!existingAlbum) {
App.dbConn.insertAlbum(album, artist);
}
}
public void checkPlaylist(String playlist) throws SQLException {
boolean existingPlaylist = App.dbConn.selectPlaylistByName(playlist) != null;
if (!existingPlaylist){
App.dbConn.insertPlaylist(playlist);
}
}
}