I have a arraylist which i want to store in database.I am using preparedStatement so how can i pass my arraylist as parameter to store it in database.

my code is:

    public void insertEnquiryRecord(StudentEnquiryEntity enquiryEntity) {
        // TODO Auto-generated method stub

        System.out.println(" hi from vivek..");

        ConnectionFactory connectionFactory = null;
        connection=connectionFactory.getConnection();

        PreparedStatement preparedStatement=null;
        ResultSet resultSet=null;

        String query1 = "insert into tbl_contmst(CLM_PHNO)values(?)";

        try{
            preparedStatement=connection.prepareStatement(query1);
            preparedStatement.setArray(1, (Array) enquiryEntity.getStudentContactList());
            //preparedStatement.setArray(2,(Array) enquiryEntity.getStudentEmailList());
             status1 = preparedStatement.executeUpdate();


            if(status1 > 0 ){
                System.out.println("Data stored Succefully");

            }


        }catch(Exception sqe){
            System.out.println("In  insertRecord:"+sqe.getMessage());
        }


    }

I seriously doubt you want to store the List. More likely you want to store the content of the List.
And you want to almost certainly store one record retrieved from the List for each row in the database.

@jwenting, yes you are right. I am not able to achieve it. can you suggest something to me?

This article has been dead for over six months. Start a new discussion instead.