Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CLASA STATIUNE
- public class Statiune {
- String statiune,tara; //nr=nr obiective
- int nr;
- public Statiune(String denumire, String tara,int nr){
- this.statiune=denumire;
- this.tara=tara;
- this.nr=nr;
- }
- public String getDenumire() {
- return statiune;
- }
- public void setDenumire(String denumire) {
- this.statiune = denumire;
- }
- public String getTara() {
- return tara;
- }
- public void setTara(String tara) {
- this.tara = tara;
- }
- public int getNr() {
- return nr;
- }
- public void setNr(int nr) {
- this.nr = nr;
- }
- public String toString() {
- return super.toString() + "Statiune[statiune=" + statiune+ ",tara=" + tara + ",nr=" + nr + "]";
- }
- }
- MAIN
- //NU UITA SA ADAUGI LA LIBRARII com.mysql.jdbc.Driver- Conectoru, da eroare fara el!!
- public static void main(String[] args)throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException{
- // TODO Auto-generated method stub
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- String url = "jdbc:mysql://localhost:3306/test";
- Connection con = DriverManager.getConnection(url, "root","test");
- // probabil va fi (url, "root", "root") la test
- Statement sql;
- sql = (Statement) con.createStatement();
- ResultSet rs;
- // ResultSet folosit doar la comenzile de Select. Comanda
- // executeUpdateQuery returneaza int si poate fi apelata pur si simplu
- int o = 0;
- BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
- do {
- System.out.println("------MENIU------");
- System.out.println("1. Afisare"); //merge
- System.out.println("2. Adaugare destinatie");
- System.out.println("3. Actualizare nr obiective pt o statiune data");
- System.out.println("4. Iesire");
- System.out.println("Optiune: ");
- try {
- o = Integer.parseInt(f.readLine());
- } catch (NumberFormatException e) {
- System.out.println("Introduceti un numar! Eroare " + e);
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- System.out.println();
- switch (o) {
- case 1:
- rs = sql.executeQuery("select * from destinatii");
- while (rs.next())
- System.out.println(rs.getString("tara") + " " + rs.getString("statiune") + " "
- + rs.getInt("Nr obiective"));
- System.out.println();
- break;
- case 2: //adaugarea nu merge
- break;
- case 3: //actualizarea nu merge
- break;
- case 4:
- break;
- default:
- System.out.println("Optiune invalida.");
- }
- } while (o != 4);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement