-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
248 lines (193 loc) · 7.62 KB
/
Player.java
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
package musicpack;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.*;
public class Player {
private String url = "jdbc:mysql://127.0.0.1/music_player";
private String username = "root";
private String password = "12345678";
Scanner console = new Scanner(System.in);
public static void AccessCol (String input) {
String url = "jdbc:mysql://127.0.0.1/music_player";
String username = "root";
String password = "12345678";
try {
Connection connection = DriverManager.getConnection(url, username, password);
//System.out.println("You are Connected to the music database!");
Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery("select SongName from music_player where SongName = " + input );
while(rs.next()) {
String SongName = rs.getString("SongName");
System.out.println("Song Name: " + SongName);
}
connection.close();
} catch (SQLException e) {
System.out.println("Oops, error!");
e.printStackTrace();
}
}
public static void AccessRow () {
String url = "jdbc:mysql://127.0.0.1/music_player";
String username = "root";
String password = "12345678";
try {
Connection connection = DriverManager.getConnection(url, username, password);
//System.out.println("You are Connected to the World database!");
Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery("select * from music_player.songs");
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
while (rs.next()) {
for(int i = 1; i <= columnsNumber; i++) {
System.out.print(rs.getString(i) + " ");
}
System.out.println();
}
connection.close();
} catch (SQLException e) {
System.out.println("Oops, error!");
e.printStackTrace();
}
}
public static void AccessRow1 (int SongID) {
String url = "jdbc:mysql://127.0.0.1/music_player";
String username = "root";
String password = "12345678";
try {
Connection connection = DriverManager.getConnection(url, username, password);
//System.out.println("You are Connected to the World database!");
Statement stat = connection.createStatement();
ResultSet rs = stat.executeQuery("select * from music_player.songs where SongID = " + SongID);
ResultSetMetaData rsmd = rs.getMetaData();
int columnsNumber = rsmd.getColumnCount();
while (rs.next()) {
for(int i = 1; i <= columnsNumber; i++) {
System.out.print(rs.getString(i) + " ");
}
System.out.println();
}
connection.close();
} catch (SQLException e) {
System.out.println("Oops, error!");
e.printStackTrace();
}
}
public static void DeleteRow(int songID) {
String url = "jdbc:mysql://127.0.0.1/music_player";
String username = "root";
String password = "12345678";
try {
Connection connection = DriverManager.getConnection(url, username, password);
//System.out.println("You are Connected to the stock_market database!");
// the mysql insert statement
String query = "delete from songs where SongID = ?";
// create the mysql insert preparedstatement
PreparedStatement preparedStmt = connection.prepareStatement(query);
preparedStmt.setInt(1, songID);
// execute the preparedstatement
preparedStmt.execute();
connection.close();
}
catch (Exception e)
{
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
}
public static void insertRow (String SongName, String artist, String album, String duration) {
String url = "jdbc:mysql://127.0.0.1/music_player";
String username = "root";
String password = "12345678";
try {
Connection connection = DriverManager.getConnection(url, username, password);
//System.out.println("You are Connected to the music_player database!");
// the mysql insert statement
String query = " insert into songs (SongName, Artist, Album, Duration)"
+ " values (?, ?, ?, ?)";
// create the mysql insert preparedstatement
PreparedStatement preparedStmt = connection.prepareStatement(query);
//preparedStmt.setInt(1, 2);
preparedStmt.setString(1, SongName);
preparedStmt.setString(2, artist);
preparedStmt.setString(3, album);
preparedStmt.setString(4, duration);
// execute the preparedstatement
preparedStmt.execute();
connection.close();
}
catch (Exception e)
{
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
}
public static void UpdateRow() {
String url = "jdbc:mysql://127.0.0.1/music_player";
String username = "root";
String password = "12345678";
try {
Connection connection = DriverManager.getConnection(url, username, password);
// System.out.println("You are Connected to the stock_market database!");
// the mysql insert statement
String query = "update stock set numShares = ? where stockID = ?";
// create the mysql insert preparedstatement
PreparedStatement preparedStmt = connection.prepareStatement(query);
preparedStmt.setInt(1, 200);
preparedStmt.setInt(2, 1);
// execute the preparedstatement
preparedStmt.execute();
connection.close();
}
catch (Exception e)
{
System.err.println("Got an exception!");
System.err.println(e.getMessage());
}
}
public static void main (String[] args) {
Scanner console = new Scanner(System.in);
System.out.println(" \n Welcome to Raoify Music Playlist \n\n You can enter the songs you want to listen to into \n the playlist!! \n The song name, song duration, artist name, album name, and duration length will all be stored. ");
System.out.println(" \n Choose an option: \n 1: Add a new song to the playlist \n 2: Remove a song from the playlist \n 3: to return a song in a certain index number \n 4: to print out the whole playlist");
boolean run = true;
while (run) {
System.out.print(" enter number: ");
int inputCommand = console.nextInt();
System.out.println();
if (inputCommand == 1) {
System.out.print(" enter Song Name: ");
String songName = console.next();
System.out.print(" enter Artist Name: ");
String artist = console.next();
System.out.print(" enter Album Name: ");
String albumName = console.next();
System.out.print(" enter Duration length: ");
String songDuration = console.next();
insertRow( songName, artist, albumName, songDuration);
System.out.println();
}
if (inputCommand == 2) {
System.out.print(" which row do you want to delete: ");
int deleteRow = console.nextInt();
DeleteRow(deleteRow);
System.out.println();
}
if (inputCommand == 3) {
System.out.print(" which row do you want to access: ");
int SongID = console.nextInt();
System.out.println();
AccessRow1(SongID);
System.out.println();
}
if (inputCommand == 4) {
System.out.println();
AccessRow();
System.out.println();
}
}
}
}