JavaWebApp创建过程

smtd7mpg  于 2021-08-25  发布在  Java
关注(0)|答案(0)|浏览(269)

我正在创建一个java web应用程序,它应该从数据库中获取数据并显示在网页上,我想提供添加和删除功能来添加和删除数据库中的条目。我已经与mysql数据库建立了连接,并设法将数据加载到对象的数组列表中。invoice类保存数据。我想知道如何使用此arraylist填充html表。我可以做些什么来添加功能。

public class invoice {
    private String customer_name;
    private String Customer_no;
    private String invoiceId;
    private double invoice_amt;
    private String due_date;
    private String predicted_dt;
    private String notes;
    public String getCustomer_name() {
        return customer_name;
    }
    public void setCustomer_name(String customer_name) {
        this.customer_name = customer_name;
    }
    public String getCustomer_no() {
        return Customer_no;
    }
    public void setCustomer_no(String customer_no) {
        Customer_no = customer_no;
    }
    public String getInvoiceId() {
        return invoiceId;
    }
    public void setInvoiceId(String invoiceId) {
        this.invoiceId = invoiceId;
    }
    public double getInvoice_amt() {
        return invoice_amt;
    }
    public void setInvoice_amt(double invoice_amt) {
        this.invoice_amt = invoice_amt;
    }
    public String getDue_date() {
        return due_date;
    }
    public void setDue_date(String due_date) {
        this.due_date = due_date;
    }
    public String getPredicted_dt() {
        return predicted_dt;
    }
    public void setPredicted_dt(String predicted_dt) {
        this.predicted_dt = predicted_dt;
    }
    public String getNotes() {
        return notes;
    }
    public void setNotes(String notes) {
        this.notes = notes;
    }
}

这是我的数据对象。它应该是表中的一行。

import java.sql.*;
import java.util.ArrayList;
public class GetData extends invoice {
    public static void main(String args[]){  
        try{  
        Class.forName("com.mysql.cj.jdbc.Driver");  
        Connection con=DriverManager.getConnection(  
        "jdbc:mysql://localhost:3307/maindata","root","root");  

        Statement stmt=con.createStatement();  
        ResultSet rs=stmt.executeQuery("select name_customer, cust_number,invoice_id,due_in_date,pred_clear_date from mytable"); 

        ArrayList<invoice> a = new ArrayList<invoice>();
        while(rs.next())  
        {

            invoice temp = new invoice();

            temp.setCustomer_name(rs.getString(1));
            temp.setCustomer_no(rs.getString(2));
            temp.setInvoiceId(rs.getString(3));
            temp.setDue_date(rs.getString(4));
            temp.setPredicted_dt(rs.getString(5));
            temp.setNotes(null);
            a.add(temp);
        }

        con.close();  
        }catch(Exception e){ System.out.println(e);}  
        }  
}

此类正在将数据获取到数组列表中。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题