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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:24:03+00:00 2026-05-24T23:24:03+00:00

Can someone suggest me a good example or link to select records from MySQL

  • 0

Can someone suggest me a good example or link to select records from MySQL and insert the records into a map so I can do the analysis in C++.
I am trying to pull in price data from the db, so I have a transaction date and sale price.
I don’t want to go through the intermediate step and write the records to a .csv file.

thx!


i was not able to get it work with sql::Connection so I used the API. I am trying to extract date and sales$’s from the db, which has other fields also. so, here is the code I have:

#include <iostream>
#include </usr/include/mysql/mysql.h>
#include </usr/include/sys/time.h> 
using namespace std;

#include <vector>
#include <iterator>
#include <string>
#include <map>

MYSQL *connection;
MYSQL mysql;
MYSQL_RES *resptr;
MYSQL_ROW row;
MYSQL_FIELD *field;

int query_state;

map<string, double> test;
string key;
double value;

int main() 
{
mysql_init(&mysql);
connection = mysql_real_connect(&mysql,"localhost","userid","pwd","schema",0,0,0);

query_state = mysql_query(connection, "select pdate, sales from test;");

 resptr = mysql_store_result(connection); 


while ( ( row = mysql_fetch_row(resptr)) != NULL ) 
{

test[resptr->getString("pdate")]=resptr->getInt("sales"); 
} 

mysql_free_result(resptr);
mysql_close(connection);

return 0;
}

but I get the following error:

error: ‘struct MYSQL_RES’ has no member named ‘getString’

error: ‘struct MYSQL_RES’ has no member named ‘getInt’
  • 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-05-24T23:24:04+00:00Added an answer on May 24, 2026 at 11:24 pm

    You will need to use the C++ connector. You can download it from this link.

    Here’s the wiki page to get you started.

    Edit: I haven’t tested this myself, but something like this should work:

    map<int, string> results;
    
    sql::mysql::MySQL_Driver* driver = sql::mysql::get_mysql_driver_instance();
    sql::Connection* con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
    
    sql::Statement* stmt = con->createStatement();
    sql::ResultSet* res = stmt->executeQuery("SELECT id, label FROM test ORDER BY id ASC");
    while (res->next())
    {
        results[res->getInt("id")] = res->getString("label");
    }
    
    delete res;
    delete stmt;
    delete con;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone suggest a good tomcat memory profiler? (I am trying to profile the
Can someone suggest a good module in perl which can be used to store
Can someone suggest me a way to map a template classes with a set
Can someone suggest good learning materials or websites to learn JavaScript and jQuery? Am
Can someone suggest some good tutorials for getting started with JAX-WS? Using various tools
Can someone help suggest a good way to achieve the following please? I want
Can someone suggest a good way to understand how MPI works?
Can Someone suggest me a good open source java library to read ECG data
Can someone suggest a good wiki for our dev team please. I know this
Can someone suggest a way to compare the values of two dates greater than,

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.