Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. CLASA STATIUNE
  2. public class Statiune {
  3. String statiune,tara; //nr=nr obiective
  4. int nr;
  5. public Statiune(String denumire, String tara,int nr){
  6. this.statiune=denumire;
  7. this.tara=tara;
  8. this.nr=nr;
  9. }
  10. public String getDenumire() {
  11. return statiune;
  12. }
  13. public void setDenumire(String denumire) {
  14. this.statiune = denumire;
  15. }
  16. public String getTara() {
  17. return tara;
  18. }
  19. public void setTara(String tara) {
  20. this.tara = tara;
  21. }
  22. public int getNr() {
  23. return nr;
  24. }
  25. public void setNr(int nr) {
  26. this.nr = nr;
  27. }
  28. public String toString() {
  29. return super.toString() + "Statiune[statiune=" + statiune+ ",tara=" + tara + ",nr=" + nr + "]";
  30. }
  31. }
  32. MAIN
  33. //NU UITA SA ADAUGI LA LIBRARII com.mysql.jdbc.Driver- Conectoru, da eroare fara el!!
  34. public static void main(String[] args)throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException{
  35. // TODO Auto-generated method stub
  36. Class.forName("com.mysql.jdbc.Driver").newInstance();
  37. String url = "jdbc:mysql://localhost:3306/test";
  38. Connection con = DriverManager.getConnection(url, "root","test");
  39. // probabil va fi (url, "root", "root") la test
  40. Statement sql;
  41. sql = (Statement) con.createStatement();
  42. ResultSet rs;
  43. // ResultSet folosit doar la comenzile de Select. Comanda
  44. // executeUpdateQuery returneaza int si poate fi apelata pur si simplu
  45.  
  46. int o = 0;
  47.  
  48. BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
  49. do {
  50. System.out.println("------MENIU------");
  51. System.out.println("1. Afisare"); //merge
  52. System.out.println("2. Adaugare destinatie");
  53. System.out.println("3. Actualizare nr obiective pt o statiune data");
  54. System.out.println("4. Iesire");
  55. System.out.println("Optiune: ");
  56. try {
  57. o = Integer.parseInt(f.readLine());
  58. } catch (NumberFormatException e) {
  59. System.out.println("Introduceti un numar! Eroare " + e);
  60. e.printStackTrace();
  61. } catch (IOException e) {
  62. e.printStackTrace();
  63. }
  64. System.out.println();
  65. switch (o) {
  66. case 1:
  67. rs = sql.executeQuery("select * from destinatii");
  68. while (rs.next())
  69. System.out.println(rs.getString("tara") + " " + rs.getString("statiune") + " "
  70. + rs.getInt("Nr obiective"));
  71. System.out.println();
  72. break;
  73. case 2: //adaugarea nu merge
  74. break;
  75. case 3: //actualizarea nu merge
  76. break;
  77. case 4:
  78. break;
  79. default:
  80. System.out.println("Optiune invalida.");
  81. }
  82. } while (o != 4);
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement