Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8447425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:10:38+00:00 2026-06-10T10:10:38+00:00

I have two arraylists to insert into 2 columns in a database table as

  • 0

I have two arraylists to insert into 2 columns in a database table as follows:

arraylist1: 123444, 324555, 6423643, 532326
arraylist2: jkfdsl, nkjfsdlj, jdslkfjdlkj, jfsldjfsk, fjdlskjfs

I wrote the following code to insert the arraylists but it is not working. I will appreciate your help.

try {
// Prepare a statement to insert a record

String sql = "INSERT INTO soundsdata.splog (arraylist1, arraylist2) VALUES(?,?)";
pstmt = (PreparedStatement) con.prepareStatement(sql);

pstmt.setArray(1,sptospring);
pstmt.setString(2,eachList.toString());

// Insert the row
pstmt.executeUpdate();
}finally {
pstmt.close();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T10:10:39+00:00Added an answer on June 10, 2026 at 10:10 am

    Here’s something that you can do:

    Assuming that you’re trying to create one row, where the 1st column will contain the content of the first ArrayList in comma-separated format and the 2nd column will contain the content of the secondArrayList

    StringBuilder buffer = new StringBuilder();
    boolean processedFirst = false;
    String firstParam = null, secondParam = null;
    
    try{
        for(String record: arrayList1){
            if(processedFirst)
                buffer.append(",");
            buffer.append(record);
            processedFirst = true;
        }
        firstParam = buffer.toString();
    }finally{
        buffer = null;
    }
    processedFirst = false;
    buffer = new StringBuilder();
    try{
        for(String record: arrayList2){
            if(processedFirst)
                buffer.append(",");
            buffer.append(record);
            processedFirst = true;
        }
        secondParam = buffer.toString();
    }finally{
        buffer = null;
    }
    secondParam = buffer.toString();
    
    String sql = "INSERT INTO soundsdata.splog (arraylist1, arraylist2) VALUES(?,?)";
    try{
        psmt = (PreparedStatement) con.prepareStatement(sql);
        pstmt.setString(1,firstParam);
        pstmt.setString(2,secondParam);
        pstmt.executeUpdate();
    }finally {
        pstmt.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrayLists and I am trying to subtract one arrayList from another.
So we have a java class with two ArrayLists of generics. It looks like
I have worked in Listview, I have stored values in arraylist1 and arraylist2, then
I have two arraylists that consist of the datetime objects and merging both the
I have two arraylists, and I would like to have a new arraylist with
I have two Arrays/ArrayLists of Integer. I want to know the optmized way to
Im developing the java Email application with Timer, I have a two arraylists named
I have two arrays (or arraylists if it is easier) of strings. I need
I have two ArrayLists, each holding blocks of certain size: blockList, eraserList. Blocks are
I have two arraylists. One contains filenames and the other contains failurecount. These values

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.