如何在java中从MySQL检索查询的结果集

Vin*_*lia 4 java mysql eclipse arraylist

我已经连接到我的数据库:

Connection con = DriverManager.getConnection(
    "jdbc:mysql://instance23389.db.xeround.com:15296/Inventory","user","password");
PreparedStatement Statement = con.prepareStatement("Select * from inventory");
ResultSet result = Statement.executeQuery();
while(result.next()) {
    //What to put here?
}
Run Code Online (Sandbox Code Playgroud)

这是我想要存储在该数据库中的arraylist:

static ArrayList<Product> Chart=new ArrayList<Product>();
Run Code Online (Sandbox Code Playgroud)

并且这些对象存储在arraylist中:

double Total;
String name;
double quantity;
String unit;
double ProductPrice;
Run Code Online (Sandbox Code Playgroud)

我需要使用什么通用代码来将arraylist存储在MySQL数据库中?我需要使用什么通用代码才能将arraylist从MySQL数据库中删除?

Rei*_*eus 11

这是用于检索和填充Arraylist的内容的模板 productList

while (result.next()) {

    Product product = new Product();

    product.setTotal(result.getDouble("Total"));
    product.setName(result.getString("Name"));
    // etc.

    productList.add(product);
}
Run Code Online (Sandbox Code Playgroud)

在此期间,我邀请您来看看:

http://www.jdbc-tutorial.com/