Guest User

Untitled

a guest
Oct 19th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 40.35 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.sql.Connection;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.sql.Statement;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10.  
  11. /**
  12. *
  13. * @author Raul
  14. *
  15. */
  16. public class Methods {
  17.  
  18. Menus m;
  19. Musicians mu = new Musicians();
  20. AccesDB a = new AccesDB();
  21. private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  22.  
  23. public void loginMenu() throws ClassNotFoundException, SQLException, IOException{
  24.  
  25. a.openConnection();
  26.  
  27.  
  28. m = new Menus();
  29. String[] i = { "Login","Login as a guest", "Exit"};
  30. m.setN(i);
  31. int op = 0;
  32. while(true){
  33. op = m.menu();
  34. switch(op){
  35. case 1: menuLevel(0);continue;
  36. case 2: menuLevel(1);continue;
  37. case 3: break;
  38. default: continue;
  39.  
  40. }
  41. break;
  42. }
  43. }
  44.  
  45.  
  46. private int login() throws IOException, SQLException, ClassNotFoundException {
  47. a.openConnection();
  48. String login,pass;
  49. int level = 0;
  50. while(true){
  51. login = getInputText("login");
  52. pass = getInputText("password");
  53. a.setUsers(login);
  54.  
  55. a.rs = a.st.executeQuery("SELECT * from users where user ='" + login +
  56. "' and password ='" + pass +"';");
  57. if(a.rs.first()){
  58. a.rs = a.st.executeQuery("SELECT * from users where user ='" + login +
  59. "' and password ='" + pass +"';");
  60. while(a.rs.next()){
  61. level = a.rs.getInt(3); a.rs.close();
  62. break;
  63. }
  64. break;
  65.  
  66. }else{
  67.  
  68. println("Incorrect User or Password, try again"); continue;
  69. }
  70.  
  71. }
  72. return level;
  73. }
  74. public void modifyGroupMenu() throws ClassNotFoundException, SQLException, IOException {
  75. Menus m = new Menus();
  76. String[] i = {"See my group","See members of my group", "Modify info of my group","Modify info of a member",
  77. "Insert a new Member","Delete a member","Back"};
  78. int op = 0;
  79. while(true){
  80. m.setN(i);
  81. op = m.menu();
  82. switch(op){
  83. case 1: listBands(2);continue;
  84. case 2: listMusics(2,getIdBand());continue;
  85. case 3: modifyInfoGroup('r');continue;
  86. case 4: modifyInfoMusician();continue;
  87. case 5: Inserts('m');continue;
  88. case 6: Deletes('m');continue;
  89. case 7: break;
  90. default: continue;
  91. }
  92. break;
  93. }
  94. }
  95.  
  96. public void menuLevel(int op) throws IOException, SQLException, ClassNotFoundException{
  97. while(true){
  98. if(op == 0){
  99. op = login();
  100. }
  101. switch(op){
  102. case 1: GuestMenu(); break;
  103. case 2: break;
  104. case 3: representantMenu(); break;
  105. case 4: break;
  106. case 5: AdminMenu(); break;
  107. }
  108.  
  109. break;
  110. }
  111. }
  112.  
  113. public void GuestMenu() throws ClassNotFoundException, SQLException{
  114. Menus m = new Menus();
  115. String[] i = {"See the next concerts","Search concerts by group", "Book a Ticket","Logout"};
  116. int op = 0;
  117. while(true){
  118. m.setN(i);
  119. op = m.menu();
  120. switch(op){
  121. case 1: SeeConcerts(1);continue;
  122. case 2: SeeConcerts(2);continue;
  123. case 3: BuyTicket();continue;
  124. case 4: break;
  125. default: continue;
  126. }
  127. break;
  128. }
  129. }
  130.  
  131.  
  132. public void BuyTicket() throws ClassNotFoundException, SQLException{
  133. SeeConcerts(1);
  134. a.openConnection();
  135. int c = getInputInt("the id of the concert you want to buy the ticket");
  136. if(comproveExistWhere())
  137.  
  138. }
  139.  
  140. public void SeeConcerts(int v) throws ClassNotFoundException, SQLException{
  141. if(comproveExist("concerts")){
  142. if(v == 1){
  143. a.openConnection();
  144. a.rs = a.st.executeQuery("select id_concert,b.NAME,c.id_hall,c.price,date,time,h.capacity,c.attendance from concerts c, bands b, halls h " +
  145. "where b.id_band = c.id_band and c.id_hall = h.id_hall and date >= CURDATE()");
  146. }else if(v == 2 ){
  147. a.openConnection();
  148. while(true){
  149. listBands(1);
  150. int b = getInputInt("Put the id of the Band that you want to see the next concerts");
  151. if(comproveExistWhere("bands","id_band",b)){
  152. a.rs = a.st.executeQuery("select id_concert,b.NAME,c.id_hall,c.price,date,time,h.capacity,c.attendance from concerts c, bands b, halls h " +
  153. "where b.id_band = c.id_band and c.id_hall = h.id_hall and date >= CURDATE() and b.id_band = " + b );
  154. break;
  155. }else{
  156. println("That id of band don't exist, try again"); continue;
  157. }
  158. }
  159.  
  160.  
  161.  
  162. }
  163. while(a.rs.next()){
  164. int id_concert = a.rs.getInt(1);
  165. String band = a.rs.getString(2);
  166. String id_hall = a.rs.getString(3);
  167. int price = a.rs.getInt(4);
  168. String date = a.rs.getString(5);
  169. String time = a.rs.getString(6);
  170. int capacity = a.rs.getInt(7);
  171. int attendance = a.rs.getInt(8);
  172. println("\n");
  173. println("ID_CONCERT: " + id_concert + "\n ----------------- "+ "\n Band: " + band + "\n HALL: " + id_hall
  174. + "\n PRICE: " + price + "\n DATE: " + date + "\n TIME: " + time + " \n Hall Capacity: "
  175. + capacity + "\n Sold Tickets: " + attendance + "\n -----------------");
  176. println("\n");
  177. }
  178. a.rs.close();
  179. a.closeConnection();
  180. }else{
  181. println("No concerts to show");
  182. }
  183.  
  184.  
  185.  
  186. }
  187.  
  188. public void representantMenu() throws ClassNotFoundException, SQLException, IOException{
  189.  
  190. Menus m = new Menus();
  191. String[] i = {"See all groups","See all musics", "Modify my group","Logout"};
  192. int op = 0;
  193. while(true){
  194. m.setN(i);
  195. op = m.menu();
  196. switch(op){
  197. case 1: listBands(1);continue;
  198. case 2: listMusics(1,0);continue;
  199. case 3: modifyGroupMenu();continue;
  200. case 4: break;
  201. default: continue;
  202. }
  203. break;
  204. }
  205. }
  206. public void AdminMenu() throws ClassNotFoundException, SQLException, IOException{
  207.  
  208. Menus m = new Menus();
  209. String[] i = {"Admin concerts","Admin bands","Admin musicians","Admin workers","Admin users","Logout"};
  210. int op = 0;
  211. while(true){
  212. m.setN(i);
  213. op = m.menu();
  214. switch(op){
  215. case 1: concertsMenu();continue;
  216. case 2: AdminGroupMenu();continue;
  217. case 3: AdminMusicMenu();continue;
  218. case 4: AdminWorkersMenu();continue;
  219. case 5: AdminUsersMenu();continue;
  220. case 6: break;
  221. default: continue;
  222. }
  223. break;
  224. }
  225. }
  226.  
  227. public void AdminWorkersMenu() throws ClassNotFoundException, SQLException, IOException{
  228. Menus m = new Menus();
  229. String[] i = {"See all Workers","See a worker","Modify Workers","Insert Workers","Delete Workers","Back"};
  230. int op = 0;
  231. while(true){
  232. m.setN(i);
  233. op = m.menu();
  234. switch(op){
  235. case 1: listWorkers(1);continue;
  236. case 2: listWorkers(2);continue;
  237. case 3: AdminModifyW();continue;
  238. case 4: AdminInsertsW();continue;
  239. case 5: AdminDeletesW();continue;
  240. case 6: break;
  241. default: continue;
  242. }
  243. break;
  244. }
  245. }
  246.  
  247. public void AdminUsersMenu() throws ClassNotFoundException, SQLException, IOException{
  248. Menus m = new Menus();
  249. String[] i = {"See all users","Modify user","Insert user","Delete user","Grant level acces","Back"};
  250. int op = 0;
  251. while(true){
  252. m.setN(i);
  253. op = m.menu();
  254. switch(op){
  255. case 1: listUsers();continue;
  256. case 2: AdminModifyU();continue;
  257. case 3: AdminInsertsU();continue;
  258. case 4: AdminDeletesU();continue;
  259. case 5: AdminGrantU();continue;
  260. case 6: break;
  261. default: continue;
  262. }
  263. break;
  264. }
  265. }
  266.  
  267. public void AdminGrantU() throws ClassNotFoundException, SQLException{
  268. listUsers();
  269. a.openConnection();
  270. while(true){
  271. String user = getInputText(" the user that you want to change level");
  272. if(comproveExistWhere3("users","user",user)){
  273. while(true){
  274. int l = getInputInt(" the level that you want to give(1-3-5)");
  275. if((l == 1) || (l == 3) || (l == 5)){
  276. a.st.executeUpdate("update users set level = " + l + " where user = '" + user + "'");
  277. break;
  278. }else{
  279. println("Incorrect level, only availables(1-3-5). Try again"); continue;
  280. }
  281. }
  282. }else{
  283. println("That user doesn't exist, try again"); continue;
  284. }
  285. break;
  286. }
  287. }
  288.  
  289. public void listUsers() throws SQLException, ClassNotFoundException{
  290. if(comproveExist("users")){
  291. a.openConnection();
  292. a.rs = a.st.executeQuery("SELECT * FROM users where level in (1,3,5)");
  293. while(a.rs.next()){
  294. int level = a.rs.getInt("level");
  295. String name = a.rs.getString("user");
  296. String pass = a.rs.getString("password");
  297. println("\n");
  298. println("\n -----------------" + "\n ID_USER: "+ name + " \n Password: " + pass + "\n Level: " + level + "\n -----------------");
  299. println("\n");
  300. }
  301. a.rs.close();
  302. a.closeConnection();
  303. }else{
  304. println("No users availables");
  305. }
  306. }
  307.  
  308. public void listWorkers(int v) throws SQLException, ClassNotFoundException{
  309. if(comproveExist("Workers")){
  310.  
  311. a.openConnection();
  312. if(v == 1){
  313. a.rs = a.st.executeQuery("SELECT id_worker,name,surname,phone,TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)," +
  314. "function,salary FROM Workers");
  315. }else if (v == 2){
  316. while(true){
  317. int f = getInputInt("the id fo the worker you want to see");
  318. if(comproveExistWhere("workers","id_worker",f)){
  319. a.rs =a.st.executeQuery("SELECT id_worker,name,surname,phone,TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)," +
  320. "function,salary FROM Workers where id_worker = " + f); break;
  321. }else{
  322. println("This worker doesn't exist, try again"); continue;
  323. }
  324. }
  325.  
  326. }
  327.  
  328. while(a.rs.next()){
  329. int id_music = a.rs.getInt("id_worker");
  330. String name = a.rs.getString("NAME");
  331. String surname = a.rs.getString("SURNAME");
  332. int phone = a.rs.getInt("PHONE");
  333. int old = a.rs.getInt("TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)");
  334. int salary =a.rs.getInt("salary");
  335. String funct = a.rs.getString("function");
  336.  
  337. println("\n");
  338. println("ID_WORKER: "+ id_music + "\n -----------------" + "\n NAME: " + name + " \n SURNAME: " + surname + "\n PHONE: " +
  339. phone + "\n YEARS OLD: " + old + "\n SALARY: " + salary + "\n FUNCTION " + funct + "\n -----------------");
  340. println("\n");
  341. }
  342. a.rs.close();
  343. a.closeConnection();
  344. }else{
  345. println("No workers availables to see");
  346. }
  347. }
  348.  
  349.  
  350. public void AdminMusicMenu() throws ClassNotFoundException, SQLException, IOException{
  351. Menus m = new Menus();
  352. String[] i = {"See all Musicians","See a Musician","Insert Musician","Delete Musician","Back"};
  353. int op = 0;
  354. while(true){
  355. m.setN(i);
  356. op = m.menu();
  357. switch(op){
  358. case 1: listMusics(1,0);continue;
  359. case 2: listMusics(3,0);continue;
  360. case 3: AdminInsertsM();continue;
  361. case 4: AdminDeletesM();continue;
  362. case 5: break;
  363. default: continue;
  364. }
  365. break;
  366. }
  367. }
  368.  
  369. public void AdminDeletesU() throws ClassNotFoundException, SQLException{
  370.  
  371. listUsers();
  372. int b = 0,m = 0;
  373. String id = getInputText(" User that you want to delete");
  374. if(comproveExistWhere3("users","user",id)){
  375. a.openConnection();
  376. a.rs = a.st.executeQuery("Select * from musicians where user = '" + id + "'");
  377. while(a.rs.next()){
  378. m = a.rs.getInt("id_music");
  379. }
  380. a.openConnection();
  381. a.rs = a.st.executeQuery("Select * from bands where representative =" + m);
  382. while(a.rs.next()){
  383. b = a.rs.getInt("id_band");
  384. }
  385.  
  386. a.openConnection();
  387. a.st.executeUpdate("update bands set representative = null where id_band = " + b);
  388. a.st.executeUpdate("update musicians set user = null where id_music =" + m);
  389. a.closeConnection();
  390. a.openConnection();
  391. a.st.executeUpdate("delete from users where user = '" + id + "'");
  392. }
  393. }
  394.  
  395. public void AdminDeletesM() throws ClassNotFoundException, SQLException{
  396.  
  397. listMusics(1,0);
  398. int b = 0;
  399. int id = getInputInt("ID of musician that you want to delete");
  400. a.openConnection();
  401. a.rs = a.st.executeQuery("Select * from bandmusic where id_music =" + id);
  402. if(a.rs.first()){
  403. while(a.rs.next()){
  404. b = a.rs.getInt("id_band");
  405. }
  406. a.openConnection();
  407. a.st.executeUpdate("DELETE from bandmusic where id_music =" + id);
  408. a.st.executeUpdate("DELETE from musicians where id_music =" + id);
  409.  
  410. a.st.executeUpdate("Update bands set num_comp = (num_comp - 1) where id_band = " + b );
  411. }else{
  412. a.st.executeUpdate("DELETE from musicians where id_music =" + id);
  413. }
  414. }
  415. public void AdminDeletesW() throws ClassNotFoundException, SQLException{
  416.  
  417. listWorkers(1);
  418. while(true){
  419.  
  420. int id = getInputInt("ID of Worker that you want to delete");
  421. if(comproveExistWhere("workers","id_worker",id)){
  422. a.openConnection();
  423. a.st.executeUpdate("DELETE from workers where id_worker =" + id);
  424. break;
  425. }else{
  426. println("This worker don't exist, try again"); continue;
  427. }
  428. }
  429.  
  430. }
  431.  
  432.  
  433. public void AdminInsertsW() throws ClassNotFoundException, SQLException, IOException{
  434. a.openConnection();
  435. String name;
  436. String surname;
  437. int phone;
  438. String age;
  439. String function;
  440. int salary;
  441.  
  442. name = getInputText("Name");
  443. surname = getInputText("Surname");
  444. phone = getInputInt("Phone");
  445. age = comproveDate("Born date(YYYY-MM-DD)");
  446. function = getInputText("FUNCTION");
  447. salary = getInputInt("Salary");
  448.  
  449. a.st.executeUpdate("Insert into workers (name,surname,phone,birth,salary,FUNCTION,user) values ('" + name + "','" + surname + "','"
  450. + phone + "','" + age + "'," + salary + " , '" + function + "' , NULL)");
  451.  
  452. }
  453.  
  454. public void AdminInsertsU() throws ClassNotFoundException, SQLException, IOException{
  455. a.openConnection();
  456. String user;
  457. String pass;
  458. int level;
  459. while(true){
  460.  
  461. user = getInputText("user");
  462. if(comproveExistWhere3("users","user",user)){
  463. println("That user already exist,try again");
  464. continue;
  465. }else{
  466. pass = getInputText("password");
  467. level = getInputInt("level");
  468. a.st.executeUpdate("Insert into users values ('" + user + "','" + pass +"', " + level + ")");
  469. break;
  470. }
  471. }
  472.  
  473.  
  474.  
  475. }
  476.  
  477.  
  478.  
  479.  
  480. public void AdminInsertsM() throws ClassNotFoundException, SQLException, IOException{
  481. a.openConnection();
  482. String name;
  483. String surname;
  484. int phone;
  485. String age;
  486. String instrument;
  487.  
  488. name = getInputText("Name");
  489. surname = getInputText("Surname");
  490. phone = getInputInt("Phone");
  491. age = comproveDate("Born date(YYYY-MM-DD)");
  492. instrument = getInputText("Instrument");
  493. a.st.executeUpdate("Insert into musicians (name,surname,phone,birth,instrument,user) values ('" + name + "','" + surname + "','"
  494. + phone + "','" + age + "','" + instrument + "',NULL)");
  495. while(true){
  496. println("Want to add this musician into a band?");
  497. String s = getInputText("Yes or No").toLowerCase();
  498. if(s.equals("yes")){
  499. while(true){
  500. a.openConnection();
  501. int b = getInputInt("the id of the band where you want to add the musician");
  502. if(comproveExistWhere("bands","id_band",b)){
  503. a.openConnection();
  504. a.rs = a.st.executeQuery("select id_music from musicians where name = '" + name + "' and surname = '" + surname + "' and phone = '" + phone + "'");
  505. while(a.rs.next()){
  506. int id_music = a.rs.getInt(1);
  507. a.st.executeUpdate("Insert into bandmusic values (" + b + "," + id_music + ")");
  508. a.st.executeUpdate("Update bands set num_comp = (num_comp + 1) where id_band = " + b);
  509. break;
  510. }
  511. break;
  512. }else{
  513. println("This id of band don't exist. Try again"); continue;
  514. }
  515. }
  516. break;
  517. }else if(s.equals("no")){
  518. break;
  519. }else{
  520. println("Enter only YES or NO"); continue;
  521. }
  522.  
  523. }
  524.  
  525. }
  526.  
  527. public void AdminGroupMenu() throws ClassNotFoundException, SQLException, IOException {
  528. Menus m = new Menus();
  529. String[] i = {"See all groups","See a group", "Modify info of a group","Insert a new Member"
  530. ,"Delete a member","Back"};
  531. int op = 0;
  532. while(true){
  533. m.setN(i);
  534. op = m.menu();
  535. switch(op){
  536. case 1: listBands(1);continue;
  537. case 2: listBands(3);continue;
  538. case 3: modifyInfoGroup('a');continue;
  539. case 4: MenuInsertMember();continue;
  540. case 5: MenuDeleteMember();continue;
  541. case 6: break;
  542. default: continue;
  543. }
  544. break;
  545. }
  546. }
  547.  
  548. public void concertsMenu() throws ClassNotFoundException, SQLException, IOException{
  549. Menus m = new Menus();
  550. String[] i = {"Add concert","Modify Concert","Delete Concert","See all concerts","Back"};
  551. int op = 0;
  552. while(true){
  553. m.setN(i);
  554. op = m.menu();
  555. switch(op){
  556. case 1: Inserts('c');continue;
  557. case 2: MenuModifyConcerts();continue;
  558. case 3: Deletes('c');continue;
  559. case 4: listConcerts();continue;
  560. case 5: break;
  561. default: continue;
  562. }
  563. break;
  564. }
  565. }
  566.  
  567. public void MenuModifyConcerts() throws ClassNotFoundException, SQLException, IOException{
  568. if(comproveExist("concerts")){
  569. Menus m = new Menus();
  570. String[] i = {"Modify Band","Modify Hall","Modify Price","Modify Date and Hour","Modify Attendance","Back"};
  571. m.setN(i);
  572. int op = 0;
  573. while(true){
  574. m.setN(i);
  575. op = m.menu();
  576. switch(op){
  577. case 1: ModifysConcert('b');continue;
  578. case 2: ModifysConcert('h');continue;
  579. case 3: ModifysConcert('p');continue;
  580. case 4: ModifysConcert('d');continue;
  581. case 5: ModifysConcert('a');continue;
  582. case 6: break;
  583. default: continue;
  584. }
  585. break;
  586. }
  587. }else{
  588. println("Don't are any concert to modify, turning back");
  589. }
  590.  
  591. }
  592. public void AdminModifyW() throws ClassNotFoundException, SQLException, IOException{
  593. if(comproveExist("workers")){
  594. Menus m = new Menus();
  595. String[] i = {"Modify Name","Modify surname","Modify phone ","Modify birth","Modify function","Modify Salary","Back"};
  596. m.setN(i);
  597. int op = 0;
  598. while(true){
  599. m.setN(i);
  600. op = m.menu();
  601. switch(op){
  602. case 1: ModifysWorkers('n');continue;
  603. case 2: ModifysWorkers('s');continue;
  604. case 3: ModifysWorkers('p');continue;
  605. case 4: ModifysWorkers('b');continue;
  606. case 5: ModifysWorkers('f');continue;
  607. case 6: ModifysWorkers('$');continue;
  608. case 7: break;
  609. default: continue;
  610. }
  611. break;
  612. }
  613. }else{
  614. println("Don't are any concert to modify, turning back");
  615. }
  616.  
  617. }
  618.  
  619. public void AdminModifyU() throws ClassNotFoundException, SQLException, IOException{
  620. if(comproveExist("workers")){
  621. Menus m = new Menus();
  622. String[] i = {"Modify password","Modify level acces ","Back"};
  623. m.setN(i);
  624. int op = 0;
  625. while(true){
  626. m.setN(i);
  627. op = m.menu();
  628. switch(op){
  629. case 1: ModifysUsers('p');continue;
  630. case 2: ModifysUsers('l');continue;
  631. case 3: break;
  632. default: continue;
  633. }
  634. break;
  635. }
  636. }else{
  637. println("Don't are any concert to modify, turning back");
  638. }
  639.  
  640. }
  641.  
  642. public void ModifysUsers(char m) throws ClassNotFoundException, SQLException, IOException {
  643. a.openConnection();
  644. listUsers();
  645. while(true){
  646.  
  647. String s = getInputText("the user that you want to modify");
  648. if(comproveExistWhere3("users","user",s)){
  649. if(m == 'p'){
  650. String surname = getInputText("the new password");
  651. a.st.executeUpdate("update users set password = '" + surname + "' where user = '" + s + "'");
  652. }else if(m == 'l'){
  653. int phone = getInputInt("the new level");
  654. a.st.executeUpdate("update users set level =" + phone + " where user = '" + s + "'");
  655. }
  656. }else{
  657. println("This user don't exist, try again"); continue;
  658. }
  659. break;
  660. }
  661.  
  662. }
  663.  
  664.  
  665.  
  666. public void ModifysWorkers(char m) throws ClassNotFoundException, SQLException, IOException {
  667. a.openConnection();
  668. listWorkers(1);
  669. while(true){
  670.  
  671. int s = getInputInt("the id of the worker you want to modify");
  672. if(comproveExistWhere("workers","id_worker",s)){
  673. if(m == 'n'){
  674. String name = getInputText("the new name");
  675. a.st.executeUpdate("update workers set name = '" + name + "' where id_worker = " + s);
  676. }else if(m == 's'){
  677. String surname = getInputText("the new surname");
  678. a.st.executeUpdate("update workers set surname = '" + surname + "' where id_worker = " + s);
  679. }else if(m == 'p'){
  680. int phone = getInputInt("the new phone");
  681. a.st.executeUpdate("update workers set phone =" + phone + " where id_worker = " + s);
  682. }else if(m == 'b'){
  683. String birth = comproveDate("New birth date(YYYY-MM-DD)");
  684. a.st.executeUpdate("update workers set birth ='" + birth +"' where id_worker = " + s);
  685. }else if(m == 'f'){
  686. String funct = getInputText("the new function");
  687. a.st.executeUpdate("update workers set function = '" + funct + "' where id_worker = " + s);
  688. }else if(m == '$'){
  689. int salary = getInputInt("the new salary");
  690. a.st.executeUpdate("update workers set salary = " + salary + " where id_worker = " + s);
  691. }
  692. }else{
  693. println("This worker don't exist, try again"); continue;
  694. }
  695. break;
  696. }
  697.  
  698. }
  699.  
  700. public void AdminInsertB(char o) throws IOException, SQLException, ClassNotFoundException{
  701. if(o == 'n'){
  702. a.openConnection();
  703. int b = getInputInt("the id of the group where you want to add the member");
  704. String name = getInputText("Name");
  705. String surname = getInputText("Surname");
  706. int phone = getInputInt("Phone");
  707. String age = comproveDate("Born date(YYYY-MM-DD)");
  708. String instrument = getInputText("Instrument");
  709. a.st.executeUpdate("Insert into musicians (name,surname,phone,birth,instrument,user) values ('" + name + "','" + surname + "','"
  710. + phone + "','" + age + "','" + instrument + "',NULL)");
  711. a.rs = a.st.executeQuery("select id_music from musicians where name = '" + name + "' and surname = '" + surname + "' and phone = '" + phone + "'");
  712. while(a.rs.next()){
  713. int id_music = a.rs.getInt(1);
  714. a.st.executeUpdate("Insert into bandmusic values (" + b + "," + id_music + ")");
  715. a.st.executeUpdate("Update bands set num_comp = (num_comp + 1) where id_band = " + b);
  716. break;
  717. }
  718. }else if (o =='e'){
  719. a.openConnection();
  720. listMusics(1,0);
  721. int b = getInputInt("the id of the group where you want to add the member");
  722. int m = getInputInt("The id of the music that you want to add to the band");
  723. a.openConnection();
  724. a.rs = a.st.executeQuery("select * from bandmusic where id_band =" + b + " and id_music = " + m);
  725. if(a.rs.first()){
  726. println("This musician is already part of this group.");
  727. }else{
  728. a.st.executeUpdate("Insert into bandmusic values (" + b + "," + m + ")");
  729. a.st.executeUpdate("Update bands set num_comp = (num_comp + 1) where id_band = " + b);
  730. }
  731. }
  732.  
  733. }
  734.  
  735. public void AdminDelete1(char o) throws ClassNotFoundException, SQLException{
  736. a.openConnection();
  737. if(o == 'd'){
  738. int b = 0;
  739. listMusics(1,0);
  740. a.openConnection();
  741. int id = getInputInt("ID from member you want to delete");
  742. a.rs = a.st.executeQuery("select id_band from bandmusic where id_music = " + id);
  743. while(a.rs.next()){
  744. b = a.rs.getInt(1);
  745. }
  746. a.openConnection();
  747. a.st.executeUpdate("DELETE from bandmusic where id_music =" + id);
  748. a.st.executeUpdate("DELETE from musicians where id_music =" + id);
  749. a.st.executeUpdate("Update bands set num_comp = (num_comp - 1) where id_band = " + b);
  750. }else if(o == 'n'){
  751. a.openConnection();
  752. int b = 0;
  753. int id = getInputInt("ID from member you want to delete");
  754. a.rs = a.st.executeQuery("select id_band from bandmusic where id_music = " + id);
  755. while(a.rs.next()){
  756. b = a.rs.getInt(1);
  757. }
  758. a.st.executeUpdate("Update bands set num_comp = (num_comp - 1) where id_band = " + b);
  759. a.st.executeUpdate("DELETE from bandmusic where id_music =" + id);
  760. }
  761.  
  762. }
  763. public void MenuInsertMember() throws ClassNotFoundException, IOException, SQLException{
  764. Menus m = new Menus();
  765. String[] i = {"Insert New Member","Add Existing Music to a group","Back"};
  766. int op = 0;
  767. while(true){
  768. m.setN(i);
  769. op = m.menu();
  770. switch(op){
  771. case 1: AdminInsertB('n');continue;
  772. case 2: AdminInsertB('e');continue;
  773. case 3: break;
  774. default: continue;
  775. }
  776. break;
  777. }
  778.  
  779. }
  780. public void MenuDeleteMember() throws ClassNotFoundException, IOException, SQLException{
  781. Menus m = new Menus();
  782. String[] i = {"Delete a member of a group and all his information","Delete a member from a group but not his information","Back"};
  783. int op = 0;
  784. while(true){
  785. m.setN(i);
  786. op = m.menu();
  787. switch(op){
  788. case 1: AdminDelete1('d');continue;
  789. case 2: AdminDelete1('n');continue;
  790. case 3: break;
  791. default: continue;
  792. }
  793. break;
  794. }
  795.  
  796. }
  797.  
  798. public void ModifysConcert(char m) throws ClassNotFoundException, SQLException, IOException{
  799.  
  800. listConcerts();
  801. int concert;
  802. while(true){
  803. a.openConnection();
  804. concert = getInputInt("the id of the concert that you want to modify");
  805. a.rs = a.st.executeQuery("Select * from concerts where id_concert = " + concert);
  806. if(a.rs.first()){
  807. if(m == 'b'){
  808. while(true){
  809. a.openConnection();
  810. int band = getInputInt("the id of the band");
  811. a.rs = a.st.executeQuery("select * from bands where id_Band =" + band);
  812. if(a.rs.first()){
  813. a.openConnection();
  814. a.st.executeUpdate("update concerts set id_band = " + band + " where id_Concert = " + concert);
  815. break;
  816. }else{
  817. println("The id that you entered is not corret or don't exist. Try again"); continue;
  818. }
  819. }
  820. }else if(m == 'h'){
  821.  
  822. while(true){
  823. a.openConnection();
  824. String hall = getInputText("the id of hall");
  825. a.rs = a.st.executeQuery("Select * from halls where id_hall = '" + hall + "'");
  826. if(a.rs.first()){
  827. a.openConnection();
  828. a.st.executeUpdate("update concerts set id_hall = '" + hall + "' where id_concert =" + concert);
  829. break;
  830. }else{
  831. println("The id that you entered is not corret or don't exist. Try again"); continue;
  832. }
  833. }
  834. }else if(m == 'p'){
  835. a.openConnection();
  836. int price = getInputInt("the price that you want");
  837. a.st.executeUpdate("update concerts set price = " + price + " where id_concert = " + concert);
  838. if(price == 0){
  839. a.openConnection();
  840. a.st.executeUpdate("update concerts set free = true where id_concert = " + concert);
  841. }else{
  842. a.openConnection();
  843. a.st.executeUpdate("update concerts set free = false where id_concert = " + concert);
  844. }
  845. }else if(m == 'd'){
  846. a.openConnection();
  847. String date = comproveDate("Insert the new date(YYYY-MM-DD)");
  848. String hour = comproveHour("Insert the new time(HH:MM)");
  849. a.st.executeUpdate("update concerts set date = '" + date +"', time = '" + hour + "' where id_concert = " + concert);
  850. }else if(m == 'a'){
  851. while(true){
  852. a.openConnection();
  853. int aten = getInputInt("How many tickets you want to reserve");
  854. int cap = 0;
  855. a.rs =a.st.executeQuery("Select * from halls h, concerts c where h.id_hall = c.id_hall and id_concert =" + concert);
  856. while(a.rs.next()){
  857. cap = a.rs.getInt(2);
  858. break;
  859. }
  860. a.openConnection();
  861. int aten1 = 0 ;
  862. a.rs = a.st.executeQuery("Select attendance from concerts where id_concert =" + concert);
  863. while(a.rs.next()){
  864. aten1= a.rs.getInt(1);
  865. break;
  866. }
  867. if((aten1 + aten) > cap){
  868. println("There are not enough tickets available. Put a smaller amount or Put 0 to exit."); continue;
  869. }else if(aten == 0){
  870. break;
  871.  
  872. }else{
  873. a.openConnection();
  874. a.st.executeUpdate("Update concerts set attendance = (attendance + " + aten + ") where id_concert = " + concert);
  875. break;
  876. }
  877.  
  878. }
  879. }
  880. break;
  881. }else{
  882. println("Incorrect id of concert. Please try again"); continue;
  883. }
  884. }
  885.  
  886. }
  887.  
  888.  
  889. public void listConcerts() throws ClassNotFoundException, SQLException{
  890. if(comproveExist("concerts")){
  891. a.openConnection();
  892. a.rs = a.st.executeQuery("Select * from concerts");
  893. while(a.rs.next()){
  894. int id_concert = a.rs.getInt("ID_CONCERT");
  895. int id_band = a.rs.getInt("ID_BAND");
  896. String id_hall = a.rs.getString("id_hall");
  897. int price = a.rs.getInt("price");
  898. String date = a.rs.getString("date");
  899. String time = a.rs.getString("time");
  900. int attendance = a.rs.getInt("ATTENDANCE");
  901. println("\n");
  902. println("ID_CONCERT: " + id_concert + "\n ----------------- "+ "\n ID_BAND: " + id_band + "\n HALL: " + id_hall
  903. + "\n PRICE: " + price + "\n DATE: " + date + "\n TIME: " + time + " \n ATTENDANCE: " + attendance + "\n -----------------");
  904. println("\n");
  905. }
  906. a.rs.close();
  907. a.closeConnection();
  908. }else{
  909. println("No concerts to show");
  910. }
  911. }
  912.  
  913.  
  914.  
  915. /**
  916. *
  917. * @param s
  918. * @throws ClassNotFoundException
  919. * @throws SQLException
  920. */
  921.  
  922. public void modifyInfoGroup(char s) throws ClassNotFoundException, SQLException{
  923. listBands(2);
  924.  
  925. Menus m = new Menus();
  926. String[] i = {"Modify Name","Modify Style","Modify Representative","Back"};
  927. m.setN(i);
  928. int op = 0;
  929. while(true){
  930. m.setN(i);
  931. op = m.menu();
  932. switch(op){
  933. case 1: ModifysBand('n',s);continue;
  934. case 2: ModifysBand('s',s);continue;
  935. case 3: ModifysBand('r',s);continue;
  936. case 4: break;
  937. default: continue;
  938. }
  939. break;
  940. }
  941.  
  942. }
  943. public void modifyInfoMusician() throws ClassNotFoundException, SQLException, IOException{
  944. Menus m = new Menus();
  945. String[] i = {"Modify name","Modify surname","Modify phone","Modify birth date","Back"};
  946. int op = 0;
  947. while(true){
  948. m.setN(i);
  949. op = m.menu();
  950. switch(op){
  951. case 1: ModifysMusic('n');continue;
  952. case 2: ModifysMusic('s');continue;
  953. case 3: ModifysMusic('p');continue;
  954. case 4: ModifysMusic('b');continue;
  955. case 5: break;
  956. default: continue;
  957. }
  958. break;
  959. }
  960.  
  961. }
  962.  
  963.  
  964. public void listBands(int v) throws SQLException, ClassNotFoundException{
  965. a.openConnection();
  966. if(v == 1){
  967. a.rs = a.st.executeQuery("SELECT * FROM bands");
  968. }else if (v == 2){
  969. int b = getIdBand();
  970. a.rs = a.st.executeQuery("select * from bands where id_band =" + b );
  971. }else if (v == 3){
  972. while(true){
  973. int b = getInputInt("the id of the group you want to see");
  974. if(comproveExistWhere("bands","id_band",b)){
  975. listMusics(2,b);
  976. a.openConnection();
  977. a.rs = a.st.executeQuery("select * from bands where id_band =" + b);
  978. break;
  979. }else{
  980. println("The id that you entered don't exist. Try again"); continue;
  981. }
  982. }
  983.  
  984. }
  985.  
  986.  
  987. while(a.rs.next()){
  988. int id_band = a.rs.getInt("ID_BAND");
  989. String name = a.rs.getString("NAME");
  990. int representative = a.rs.getInt("REPRESENTATIVE");
  991. int num_comp = a.rs.getInt("NUM_COMP");
  992. String style = a.rs.getString("STYLE");
  993. println("\n");
  994. println("ID_BAND: " + id_band + "\n ----------------- "+ "\n NAME: " + name + "\n REPRESENTATIVE: " + representative
  995. + "\n Number of members: " + num_comp + "\n Style: " + style + "\n -----------------");
  996. println("\n");
  997. }
  998. a.rs.close();
  999. a.closeConnection();
  1000.  
  1001. }
  1002.  
  1003. public void listMusics(int v,int b) throws ClassNotFoundException, SQLException{
  1004. a.openConnection();
  1005. if(v == 1){
  1006. a.rs = a.st.executeQuery("SELECT id_music,name,surname,phone,TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)," +
  1007. "instrument FROM musicians");
  1008. }else if (v == 2){
  1009. a.rs =a.st.executeQuery("SELECT m.id_music,name,surname,phone,TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)," +
  1010. "instrument FROM musicians m,bandmusic bm where m.id_music = bm.id_music and bm.id_band =" + b );
  1011. }else if (v == 3) {
  1012. int m =getInputInt("Enter the id of the Musician that want to see");
  1013. if(comproveExistWhere("musicians","id_music",m)){
  1014. a.rs =a.st.executeQuery("SELECT id_music,name,surname,phone,TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)," +
  1015. "instrument FROM musicians m where id_music =" + m );
  1016. }else{
  1017. println("That musician don't exist");
  1018. }
  1019.  
  1020. }
  1021. while(a.rs.next()){
  1022. int id_music = a.rs.getInt("ID_MUSIC");
  1023. String name = a.rs.getString("NAME");
  1024. String surname = a.rs.getString("SURNAME");
  1025. int phone = a.rs.getInt("PHONE");
  1026. int old = a.rs.getInt("TRUNCATE(DATEDIFF(CURDATE(), birth)/365.25, 0)");
  1027. String instrument =a.rs.getString("INSTRUMENT");
  1028.  
  1029. println("\n");
  1030. println("ID_MUSIC: "+ id_music + "\n -----------------" + "\n NAME: " + name + " \n SURNAME: " + surname + "\n PHONE: " +
  1031. phone + "\n YEARS OLD: " + old + "\n INSTRUMENT: " + instrument + "\n -----------------");
  1032. println("\n");
  1033. }
  1034. a.rs.close();
  1035. a.closeConnection();
  1036. }
  1037.  
  1038. private int getIdBand() throws ClassNotFoundException, SQLException{
  1039. a.openConnection();
  1040. int id = 0;
  1041.  
  1042. String user = a.getUsers();
  1043. a.rs = a.st.executeQuery("Select b.id_band from bands b, musicians m where" +
  1044. " m.id_music = b.representative and m.user = '" + user + "';");
  1045. while (a.rs.next()){
  1046. id = a.rs.getInt("ID_BAND");
  1047. }
  1048.  
  1049. return id;
  1050.  
  1051. }
  1052.  
  1053.  
  1054.  
  1055.  
  1056. public void ModifysBand(char m,char s) throws ClassNotFoundException, SQLException{
  1057. if(s == 'r'){
  1058. a.openConnection();
  1059. if(m == 'n'){
  1060. String name = getInputText("the new name");
  1061. a.st.executeUpdate("update bands set name = '" + name + "' where id_band = " + getIdBand());
  1062. }else if(m == 's'){
  1063. String style = getInputText("the new style");
  1064. a.st.executeUpdate("update bands set style = '" + style + "' where id_band =" + getIdBand());
  1065. }else if(m == 'r'){
  1066. println("Only admins are allowed to do it");
  1067. }
  1068. }else if(s == 'a'){
  1069. a.openConnection();
  1070. while(true){
  1071. int b = getInputInt("the id of the group that you want to modify");
  1072. if(comproveExistWhere("bands","id_band",b)){
  1073. if(m == 'n'){
  1074. String name = getInputText("the new name");
  1075. a.st.executeUpdate("update bands set name = '" + name + "' where id_band = " + b);
  1076. break;
  1077. }else if(m == 's'){
  1078. String style = getInputText("the new style");
  1079. a.st.executeUpdate("update bands set style = '" + style + "' where id_band =" + b);
  1080. break;
  1081. }else if(m == 'r'){
  1082. listMusics(2,b);
  1083. int r = 0;
  1084. String u = null;
  1085. int id = getInputInt("the id of the new presentative");
  1086. a.openConnection();
  1087. a.rs = a.st.executeQuery("select representative from bands where id_band = " + b);
  1088. while(a.rs.next()){
  1089. r = a.rs.getInt(1);
  1090. }
  1091. a.openConnection();
  1092. a.rs = a.st.executeQuery("select user from musicians where id_music = " + r );
  1093. while(a.rs.next()){
  1094. u = a.rs.getString(1);
  1095. }
  1096. System.out.println(u);
  1097. a.openConnection();
  1098. a.st.executeUpdate("update musicians set user = null where id_music =" + r);
  1099. a.openConnection();
  1100. a.st.executeUpdate("Delete from users where user = '" + u + "'");
  1101.  
  1102.  
  1103. a.openConnection();
  1104. a.rs = a.st.executeQuery("Select * from bandmusic,bands b where b.id_band = " + b + " and id_music = " + id);
  1105. if(a.rs.first()){
  1106. a.openConnection();
  1107. a.st.executeUpdate("update bands set REPRESENTATIVE = " + id +" where id_band =" + b);
  1108. String v = CreateUser(3);
  1109. a.openConnection();
  1110. a.st.executeUpdate("update musicians set user = '" + v + "' where id_music = " + id);
  1111. }
  1112. break;
  1113.  
  1114. }
  1115. }else{
  1116. println("That id of band don't exist");continue;
  1117. }
  1118. }
  1119. }
  1120. }
  1121.  
  1122. public String CreateUser(int l) throws SQLException, ClassNotFoundException{
  1123. while(true){
  1124. String u = getInputText("the user");
  1125. if(comproveExistWhere3("users","user",u)){
  1126. println("This users already exist, try again"); continue;
  1127. }else{
  1128.  
  1129. String p = getInputText("the password");
  1130. a.openConnection();
  1131. a.st.executeUpdate("Insert into users values ('" + u + "' , '" + p + "'," + l + ")");
  1132. return u;
  1133. }
  1134. }
  1135. }
  1136.  
  1137.  
  1138. public void ModifysMusic(char m) throws ClassNotFoundException, SQLException, IOException {
  1139. a.openConnection();
  1140. int s = getInputInt("the id of the member you want to modify");
  1141. if(m == 'n'){
  1142. String name = getInputText("the new name");
  1143. a.st.executeUpdate("update musicians set name = '" + name + "' where id_music = " + s);
  1144. }else if(m == 's'){
  1145. String surname = getInputText("the new surname");
  1146. a.st.executeUpdate("update musicians set surname = '" + surname + "' where id_music = " + s);
  1147. }else if(m == 'p'){
  1148. int phone = getInputInt("the new phone");
  1149. a.st.executeUpdate("update musicians set phone =" + phone + " where id_music = " + s);
  1150. }else if(m == 'b'){
  1151. String birth = comproveDate("New birth date(YYYY-MM-DD)");
  1152. a.st.executeUpdate("update musicians set birth ='" + birth +"' where id_music = " + s);
  1153. }
  1154.  
  1155. }
  1156.  
  1157. public void Inserts(char o) throws IOException, SQLException, ClassNotFoundException{
  1158. a.openConnection();
  1159. String name;
  1160. String surname;
  1161. int phone;
  1162. String age;
  1163. String instrument;
  1164.  
  1165. if(o == 'm'){
  1166. name = getInputText("Name");
  1167. surname = getInputText("Surname");
  1168. phone = getInputInt("Phone");
  1169. age = comproveDate("Born date(YYYY-MM-DD)");
  1170. instrument = getInputText("Instrument");
  1171. a.st.executeUpdate("Insert into musicians (name,surname,phone,birth,instrument,user) values ('" + name + "','" + surname + "','"
  1172. + phone + "','" + age + "','" + instrument + "',NULL)");
  1173. a.rs = a.st.executeQuery("select id_music from musicians where name = '" + name + "' and surname = '" + surname + "' and phone = '" + phone + "'");
  1174. while(a.rs.next()){
  1175. int id_music = a.rs.getInt(1);
  1176. a.st.executeUpdate("Insert into bandmusic values (" + getIdBand() + "," + id_music + ")");
  1177. a.st.executeUpdate("Update bands set num_comp = (num_comp + 1) where id_band = " + getIdBand());
  1178. break;
  1179. }
  1180. }else if( o == 'c'){
  1181. int id_band = getInputInt("ID of the band");
  1182. String id_hall = getInputText("ID of the hall");
  1183. int price = getInputInt("Price of the concert");
  1184. String date = comproveDate("Date of the concert(YYYY-MM-DD)");
  1185. String time = comproveHour("time when the concert starts(HH:MM)");
  1186. boolean free;
  1187. if(price > 0){
  1188. free = false;
  1189. }else{
  1190. free = true;
  1191. }
  1192. a.st.executeUpdate("insert into concerts(id_band,id_hall,free,price,date,time) values (" + id_band +",'" + id_hall
  1193. + "'," + free +"," + price + ",'" + date + "','" + time + "')" );
  1194. }
  1195. a.closeConnection();
  1196.  
  1197. }
  1198.  
  1199. public void Deletes(char o) throws SQLException, ClassNotFoundException{
  1200. a.openConnection();
  1201. if(o == 'm'){
  1202.  
  1203. listMusics(2,getIdBand());
  1204. a.openConnection();
  1205. while(true){
  1206.  
  1207. int id = getInputInt("ID from member you want to delete");
  1208. if(comproveExistWhere("musicians","id_music", id)){
  1209. if(comproveExistWhere2("bandmusic","id_music",id,"id_band",getIdBand())){
  1210. a.openConnection();
  1211. a.st.executeUpdate("Update bands set num_comp = (num_comp - 1) where id_band = " + getIdBand());
  1212. a.st.executeUpdate("DELETE from bandmusic where id_music =" + id);
  1213. break;
  1214. }else{
  1215. println("That musiciant aren't part of your group, try again"); continue;
  1216. }
  1217. }else{
  1218. println("That member don't exist, try again"); continue;
  1219. }
  1220.  
  1221. }
  1222.  
  1223. }else if(o == 'c'){
  1224. while(true){
  1225. int id = getInputInt("ID from concert you want to delete");
  1226. if(comproveExistWhere("concerts","id_concert",id)){
  1227. a.st.executeUpdate("DELETE from concerts where id_concert =" + id);
  1228. break;
  1229. }else{
  1230. println("That concert don't exist, try again.");continue;
  1231. }
  1232. }
  1233.  
  1234. }
  1235. }
  1236.  
  1237.  
  1238.  
  1239. public String comproveDate(String g) throws IOException{
  1240. while (true) {
  1241. println(g);
  1242. String f = br.readLine().toLowerCase();
  1243. Pattern pat = Pattern.compile("^([0-9]{4}-(0[0-9]|10|11|12)-([0-2][0-9]|[3][0-1]))");
  1244. Matcher m = pat.matcher(f);
  1245. if (!m.matches()) {
  1246. println("Error try again(YYYY-MM-DD)"); continue;
  1247. } else {
  1248. return f;
  1249. }
  1250. }
  1251. }
  1252. public String comproveHour(String g) throws IOException{
  1253. while (true) {
  1254. println(g);
  1255. String f = br.readLine().toLowerCase();
  1256. Pattern pat = Pattern.compile("^([0-2][0-9]:[1-6][0-9])");
  1257. Matcher m = pat.matcher(f);
  1258. if (!m.matches()) {
  1259. println("Error try again(HH:MM)"); continue;
  1260. } else {
  1261. return f;
  1262. }
  1263. }
  1264. }
  1265.  
  1266. public String getInputText(String quest){
  1267.  
  1268. String aux = "";
  1269. while(true){
  1270. System.out.println("Enter "+ quest + ":");
  1271. try {
  1272. aux = br.readLine();
  1273. if (aux.isEmpty()){
  1274. continue;
  1275. }else{
  1276. break;
  1277. }
  1278. } catch (IOException e) {
  1279.  
  1280. e.printStackTrace();;
  1281. }
  1282. }
  1283. return aux;
  1284. }
  1285.  
  1286.  
  1287. public int getInputInt(String quest){
  1288.  
  1289. int aux;
  1290. String s;
  1291. while(true){
  1292. System.out.println("Enter "+ quest + ":");
  1293. try {
  1294. s = br.readLine();
  1295. if (s.isEmpty()){
  1296. continue;
  1297. }else{
  1298. aux = Integer.parseInt(s);
  1299. break;
  1300.  
  1301. }
  1302. } catch (IOException e) {
  1303.  
  1304. e.printStackTrace();
  1305. } catch (NumberFormatException e1){
  1306. println("Insert only a number");
  1307. continue;
  1308. }
  1309. }
  1310. return aux;
  1311. }
  1312.  
  1313.  
  1314. public boolean comproveExist(String t) throws SQLException, ClassNotFoundException{
  1315. a.openConnection();
  1316. a.rs = a.st.executeQuery("Select * from " + t);
  1317. if(a.rs.first()){
  1318. return true;
  1319. }else{
  1320. return false;
  1321. }
  1322. }
  1323. public boolean comproveExistWhere(String t,String c,int c1) throws SQLException, ClassNotFoundException{
  1324. a.openConnection();
  1325. a.rs = a.st.executeQuery("Select * from " + t + " where " + c +" = " + c1 );
  1326. if(a.rs.first()){
  1327. return true;
  1328. }else{
  1329. return false;
  1330. }
  1331. }
  1332. public boolean comproveExistWhere3(String t,String c,String c1) throws SQLException, ClassNotFoundException{
  1333. a.openConnection();
  1334. a.rs = a.st.executeQuery("Select * from " + t + " where " + c +" = '" + c1 + "'" );
  1335. if(a.rs.first()){
  1336. return true;
  1337. }else{
  1338. return false;
  1339. }
  1340. }
  1341.  
  1342. public boolean comproveExistWhere2(String t,String c,int c1, String d, int d1) throws SQLException, ClassNotFoundException{
  1343. a.openConnection();
  1344. a.rs = a.st.executeQuery("Select * from " + t + " where " + c +" = " + c1 + " and " + d + " = " + d1);
  1345. if(a.rs.first()){
  1346. return true;
  1347. }else{
  1348. return false;
  1349. }
  1350. }
  1351.  
  1352. private void println(String f){
  1353. System.out.println(f);
  1354.  
  1355. }
  1356. }
Add Comment
Please, Sign In to add comment