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 8693331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:31:30+00:00 2026-06-13T00:31:30+00:00

I have below class file. If I try to insert values from Vector to

  • 0

I have below class file. If I try to insert values from Vector to database, then it will display below error. I want to use Vector in this case and looking how to resolve this issue.

error : The method setString(int, String) in the type PreparedStatement is not applicable for the arguments (int, Object) 

below is the class code:

public class ReadExcelFile {

        public static void main(String[] args) {

                String fileName = "C:\\excelFile.xls";
                Vector dataHolder = ReadCSV(fileName);
                printCellDataToConsole(dataHolder);
        }

        public static Vector ReadCSV(String fileName) {
                Vector cellVectorHolder = new Vector();

                try {
                        FileInputStream myInput = new FileInputStream(fileName);

                        POIFSFileSystem myFileSystem = new POIFSFileSystem(myInput);

                        HSSFWorkbook myWorkBook = new HSSFWorkbook(myFileSystem);

                        HSSFSheet mySheet = myWorkBook.getSheetAt(0);

                        Iterator rowIter = mySheet.rowIterator();

                        while (rowIter.hasNext()) {
                                HSSFRow myRow = (HSSFRow) rowIter.next();
                                Iterator cellIter = myRow.cellIterator();
                                Vector cellStoreVector = new Vector();
                                while (cellIter.hasNext()) {
                                        HSSFCell myCell = (HSSFCell) cellIter.next();
                                        cellStoreVector.addElement(myCell);
                                }
                                cellVectorHolder.addElement(cellStoreVector);
                        }
                } catch (Exception e) {
                        e.printStackTrace();
                }
                return cellVectorHolder;
        }

        public static void printCellDataToConsole(Vector dataHolder) {

                for (int i = 0; i < dataHolder.size(); i++) {
                        Vector cellStoreVector = (Vector) dataHolder.elementAt(i);
                     //   System.out.println(cellStoreVector);
                        for (int j = 0; j < cellStoreVector.size(); j++) {
                              HSSFCell myCell = (HSSFCell) cellStoreVector.elementAt(j);
                              String stringCellValue = myCell.toString();
                              System.out.print(stringCellValue + "\t\t");
                        }
                        System.out.println();
                }
        }


}

//below is the database query

String sql = "INSERT INTO table_name(EMP_ID,FNAME, LNAME, CATEGORY, DEPARTMENT, Title, REASON, Manager, sDate, eDate, ID) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
PreparedStatement pst1 = conn.prepareStatement(sql);
pst1.setString(1, cellStoreVector.get(0));
pst1.setString(2, cellStoreVector.get(1));
pst1.setString(3, cellStoreVector.get(2));
pst1.setString(4, cellStoreVector.get(3));
pst1.setString(5, cellStoreVector.get(4));
pst1.setString(6, cellStoreVector.get(5));
pst1.setString(7, cellStoreVector.get(6));
pst1.setString(8, cellStoreVector.get(7));
pst1.setString(9, cellStoreVector.get(8));
pst1.setString(10, cellStoreVector.get(9));
pst1.setString(11, "555");  //Hardcoded for testing. 
pst1.execute();
  • 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-13T00:31:31+00:00Added an answer on June 13, 2026 at 12:31 am

    Your Vector is defined to hold Objects.

    The Vector#get will return an Object.

    The PreparedStatement#setString method is expecting a String, this is a simple type mismatch issue.

    You can declare you Vector so that it only contains String…

    Vector<String> myVector = new Vector<String>(25);
    

    …But I don’t think you can from your example…

    You can cast the value in the Vector to a String

    pst1.setString(1, (String)cellStoreVector.get(0));
    

    But this is dangerous as you won’t find out that the Vector doesn’t contain a String element until run-time

    Or you can let the PreparedStatement handle it…

    pst1.setObject(1, cellStoreVector.get(0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure which is as given below: class File { public
I have my code below. It correctly reads my sqlite database file(that i have
I have the below mentioned code in a seperate class file for establishing connection
I have a template file: 'template.txt' like below: class Core_Model_DbTable_{table_name} extends YouNet_Db_Table { const
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have a class like the one below: class Foo { private: std::map<std::string, Bar*>
I have the code below : public class Anything { public int Data {
I have three model classes that look as below: class Model(models.Model): model = models.CharField(max_length=20,
I have a model defined as below: class Example(models.Model): user = models.ForeignKey(User, null=True) other
Does making the below class final (adding public final class) have any real impact

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.