【发布时间】:2018-12-30 23:38:47
【问题描述】:
我有 3 个类,一个主类,一个产品类和一个数据库类。 我的问题是如何将产品类中的对象传递给数据库类并在其上运行方法。
products class
private int product_id;
private String product_name;
private Double product_price;
//getters and setters
public void contructObjects() {
//using JSoup to scrape data from the web and form objects in a loop here.
}
database class
//using hibernate
public void initialise () {
//code that configures connection and other stuff
}
public void addproduct() {
//starts connection to database
Products product = new Products();
product.contructOjects(); //database class runs method in products class, get objects and hold them here.
}
public void shutdown() {
//stops session
}
main class
Database database = new Database();
database.initialise();
database.addproduct(); //main class gets obejcts held in database class stores them in databse.
database.shutdown();
【问题讨论】:
标签: java hibernate class object