Example:i have a database name base1,with one table(product) and data inside her:productid,name,price.
How to create a class for that table product?
Tnx in advance.
public class Product {
private int id;
private String name;
private double price;
public Product(String name) {
this.name = name;
this.id = id;
}
private String getName() {
return name;
}
private String getId() {
return id;
}
private double getPrice() {
return price;
}
i know how to create connection with database,and how to implements methods like insert,delete…but i’m having problem with creating a class.
or…something like this?
public class Proizvod {
private int id;
private String naziv;
private String sifra;
public Proizvod() {
}
public Proizvod(int id, String naziv, String sifra) {
this.id = id;
this.naziv = naziv;
this.sifra = sifra;
}
private int getId() {
return id;
}
private void setId(int id) {
this.id = id;
}
private String getNaziv() {
return naziv;
}
private void setNaziv(String naziv) {
this.naziv = naziv;
}
private String getSifra() {
return sifra;
}
private void setSifra(String sifra) {
this.sifra = sifra;
}
public void prikaziPodatke() {
System.out.println("Proizvod:" + naziv+""+id+""+sifra);
}
}
As npinti suggested, I strongly second take a look at Hibernate. With the Hibernate Tools, it generates all of the classes automatically. The first steps to make it running a little bit hard though. Hibernate Tools is a plugin can be installed into Eclipse, or Netbeans comes with it (it or a similar tool but does the same thing).