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

  • Home
  • SEARCH
  • 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 8022133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:10:51+00:00 2026-06-04T22:10:51+00:00

I have a simple table called mytable2 with only one column, name as varchar2(20).

  • 0

I have a simple table called mytable2 with only one column, name as varchar2(20).
I now have a list of names stored as vector of std::string to be inserted into the table.
I want to use executeArrayUpdate, so I must do the setDataBuffer first.
However, as I could see, people always use char[][20] to set databuffer.

This leaves me a big headache, since I have two issues here, first is to convert from vector to array, second is to convert the string to char.

1st, I tired to use vector of char[20], and this doesn’t compile. Googled and they say that vector can’t take char[], so I changed my vector of std::string to vector of char*.

2nd, I tried to turn the vector to arrray by using “void* p=&names[0]”, as some people say this way we can use vectors just as array.

I used stmt->setDataBuffer(1,mystring,OCCI_SQLT_STR,20,NULL), and the program compiled and executed alright, but when I “select name from mytable2”, it showed only some strange charaters.

Anyone has had a similiar issue before? what should I do?

My code is simple as below:

    count=2;
    vector<char*> mystring;
    for(int i=0;i<count;i++)
    {
        char my[20];
        strcpy_s(my,"Michael");
        mystring.insert(mystring.end(),my);
             }
    stmt->setDataBuffer(1,&mystring[0],OCCI_SQLT_STR,20,NULL);

    stmt->setBatchErrorMode (true);

    stmt->executeArrayUpdate(count);
  • 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-04T22:10:52+00:00Added an answer on June 4, 2026 at 10:10 pm

    You’d need to dynamically create the char array you’re putting into the vector for it to have a chance of working correctly.

    I have not used OCCI, but if I had to use API that asked for char[][20], I would give it char[][20]

    If you have your existing data in vector, why not just copy it across into the 2D char array? Eg.

    // intialise vector with nonsense
    unsigned int const VEC_SIZE = 2 ;
    vector<string> v;
    for (unsigned int i = 0; i < VEC_SIZE; ++i) {
        stringstream s;
        s << "Jon Paul " << i << endl;
        v.push_back ( s.str() ) ;
    }
    
    // create the required 2D char array
    unsigned int const STR_LEN = 20 ;
    char c [VEC_SIZE][STR_LEN];
    
    // copy the data from the vector of strings to the 2D char array
    for (unsigned int i = 0; i < VEC_SIZE; ++i) {
        string s = v[i].substr(0,STR_LEN);
        char const * const cc = s.c_str();      
        unsigned int j = 0;
        for (; j < STR_LEN && j < s.size(); ++j) {
            c[i][j] = cc[j];
        }
        c[i][ j==STR_LEN ? 20 : j ] = 0; // write NULL character
    }
    

    I take it you’ve simplified your example to be a fixed size vector, so my response is going to be simplified to, with the thorny issue of dynamic allocation of 2D arrays left as an exercise for the reader…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple table called 'message' consisting of an 'id' column and a
I have a simple table with just name and email called name_email. I am
I have a simple but huge table called 'dictionary' which has 2 columns. Id
I am trying to make a simple reservation system. I have a table called
I have a simple table with about 200k unique IDs. Now I want to
I have a simple table called News . I'm using Entity Framework to generate
Say I have a table called Employee (has ID , NAME , ADDRESS ,
I have a simple SQLite table called message: sequence INTEGER PRIMARY KEY type TEXT
I have a table called keywords. It's simple, two columns - id and keyword.
I have a very simple table called genre , which looks like this: GENRE

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.