LaĦiru M Pąrąnąvithąną LaĦiru M Pąrąnąvithąną - 3 months ago 21
Java Question

How To Pass Values Into Database using ArrayList Object using OOP concept

I'm try to pass values into database, I'm trying to get Input by User and Pass it to Database via another class called Custmer.class.And i have create getter/Setters in Other class. Can someone please help me to do this.

Here's my Custmr.class code

public class Custmer {

ArrayList<String> arrlist = new ArrayList<String>();
public void Custmer(ArrayList arrlist){
this.arrlist= arrlist;

//return msg;
Connection con;
public void passingMsg(ArrayList<Inquiries> arrlist){
try {
System.out.println("Method "+arrlist);
String sq = "INSERT INTO Inquiries (name,mail,tp,msg)VALUES(?,?,?)";
PreparedStatement pr = con.prepareStatement(sq);

for(int i=0;i<arrlist.size();i++){
//don't know how to do here's onward
} catch (SQLException ex) {

and this is how i got user input(I want to Use OOP concept)

String name = txtName.getText();
String mail = txtEmail.getText();
String tp = txtTp.getText();
String msg = txtMsg.getText();

ArrayList<String> arrlist = new ArrayList<String>();

Custmer c =new Custmer();

And I have wrote all the getter and setters in Inquiries Class

Can some one please help me to complete


1.Create a class Inquiry with attributes you need and provide getter and setter methods.

class Inquiry{
    String name;
    String mail;
    String tp;
    String message;

    public Inquiry(String name,String mail,String tp,String message){ = name;
        this.mail = mail; = tp;
        this.message = message;

    public String getName() {
        return name;
    public void setName(String name) { = name;
    public String getMail() {
        return mail;
    public void setMail(String mail) {
        this.mail = mail;
    public String getTp() {
        return tp;
    public void setTp(String tp) { = tp;
    public String getMessage() {
        return message;
    public void setMessage(String message) {
        this.message = message;
  1. Change String to Inquiry in below line

    ArrayList<String> arrlist = new ArrayList<String>(); 
  2. While adding Inquiry to ArrayList, add like this

    arrlist.add(new Inquiry(name,mail,tp,message)); 
  3. Provide values of Inquiry object into insert statement values by using getter methods of each value.