# Shkenca > Informatikë dhe Internet > Arti i programimit >  Java - Si punon Java me Database

## Pogradecari

te treja keto klasa jane ne nje pakete qe quhet "test1"





package test1;
import java.io.*;

public class Input {
  public static void main(String[] args) throws Exception {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Select Choice:");
    System.out.println("1. Shto Makine");
    System.out.println("2. Shiko Makinat ne Liste");

    String choice = reader.readLine();
    if(choice.equals("1")) {
       System.out.println("Ju lutem shkruaj Modelin e Makines:");
       String model = reader.readLine();

       System.out.println("Ju lutem shkruani vitin e prodhimit te makines:");
       int viti = Integer.valueOf(reader.readLine()).intValue();

       System.out.println("Ju lutem shkruani cmimin e makines:");
       double cmimi = Double.valueOf(reader.readLine()).doubleValue();

       System.out.println("Ju lutem shkruani ngjyren e makines:");
       String ngjyre = reader.readLine();

       Makine makine = new Makine();
       makine.ver_Model(model);
       makine.ver_Vitin(viti);
       makine.ver_Cmimin(cmimi);
       makine.ver_Ngjyren(ngjyre);

       MakineService.addMakine(makine);
    }
    else {
      MakineService.listMakinat();
    }
  }
}
==================================================  ==================================================  ==============================================







package test1;
public class Makine {
 //property of the Makine
 private int viti;
 private double cmimi;
 private String model;
 private String ngjyre;

 public void ver_Vitin(int Vitin_i_ri) {
         viti = Vitin_i_ri;
 }
 public void ver_Cmimin(double Cmimin_i_ri) {
         cmimi = Cmimin_i_ri;
 }
 public void ver_Model(String Model_i_ri) {
         model = Model_i_ri;
}
  public void ver_Ngjyren(String Ngjyren_e_re) {
   ngjyre = Ngjyren_e_re;
}
  public String gjej_Model() {
    return model;
  }
  public double gjej_Cmimin() {
    return cmimi;
  }
  public int gjej_Vitin() {
    return viti;
  }
 public String gjej_Ngjyren() {
    return ngjyre;
  }

  }
==================================================  ==================================================  ==============================================



package test1;

import java.sql.*;
import java.util.*;

public class MakineService {

  public static void addMakine(Makine Makine) throws Exception{
     Connection connection = createConnection();
connection.createStatement().executeUpdate("INSERT INTO Makine(model, ngjyre, viti, cmimi) VALUES ('" + Makine.gjej_Model() + "', '"  + Makine.gjej_Ngjyren()+ "', " + Makine.gjej_Vitin() + ", "  + Makine.gjej_Cmimin()+ ")" );
  connection.close();
   }
  public static void deleteMakine(Makine makine) throws Exception{
  }
  public static void listMakinat() throws Exception{
    Connection connection = createConnection();
ResultSet rs = connection.createStatement().executeQuery("SELECT model, ngjyre,viti, cmimi FROM Makine");
    while(rs.next()) {
      String model = rs.getString(1);
      String ngjyre = rs.getString(2);
      int viti = rs.getInt(3);
      double cmimi = rs.getDouble(4);


      System.out.println(model + " " + viti + " " + cmimi + " " + ngjyre + " " );
    }
 connection.close();

  }
  public static Connection createConnection() throws Exception{
  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  Connection connection = DriverManager.getConnection("jdbc:odbc:Makine", " "," ");
  return connection;
  }
         public static void main(String[] args)throws Exception {
  Makine mercedes = new Makine();
  mercedes.ver_Vitin(1999);
  mercedes.ver_Cmimin(10000);
  mercedes.ver_Model("Mercedes");
  mercedes.ver_Ngjyren("E Kuqe");

  Makine bmw = new Makine();
  bmw.ver_Vitin(2002);
  bmw.ver_Cmimin(15000);
  bmw.ver_Model("BMW");
  bmw.ver_Ngjyren("E Zeze");

  MakineService.addMakine(mercedes);
  MakineService.addMakine(bmw);


  }
}
==================================================  ==================================================  ==============================================




qe te krijohet lidhja 

click
control panel
click
administrative tools
click
Data Sources ODBC
click
System DSN
click Add
select microsoft Access Driver

click finish

atje ku eshte Data Source Name shtyp Makine
pastaj click Select

gjejeni atje ku i save Database Makine
dhe shtyp OK ne te gjithe boxet

por me perpara duhet krijuar nje tabele si kjo me poshte

----------

