user1118700
user1118700

Reputation: 67

Connecting mysql with vc++

I am Trying to connect mysql to vc++ from last 7 days. But nobody here to give me exaclty answer what i required.

I just want to make a simple connection from mysql. Please tell me what are the requirement i will be needed. from my sense I have downloaded Visual c++ Developer tool. mysql serve for handing database and table. And lastly mysql connector for c++. i have done everything even the simple code i have executed. I am almost irrirated by this http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html

because its not given properly should i need to add mysql main include and opt directory or or mysqlconnector directory because both are having same file.

My code is

// MYSqlTesting3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<winsock.h>
#include<stdio.h>
#include "mysql_driver.h" 
#include "mysql_connection.h"

#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#include<iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
 sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;
  sql::PreparedStatement *pstmt;

/* Create a connection */
  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
  /* Connect to the MySQL test database */
  con->setSchema("test");

  stmt = con->createStatement();
  stmt->execute("DROP TABLE IF EXISTS test");
  stmt->execute("CREATE TABLE test(id INT)");
  delete stmt;


//  delete con;

    return 0;
}

My error

error LNK2019: unresolved external symbol _get_driver_instance referenced in function _wmain

What else i need to do. I am seeking even everyforum help.But no website has given me any output. and in this link http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-apps-windows-visual-studio.html if i am choosing my mysql server include and lib directory for the following. from where 'mysqlcppconn.dll' will come.Because it i dont write it will unable to link. I have searchd every website which can show a successfull example to link mysql with c++ with problem requirement. Even for this " sql::Driver *driver;" Intellisense is not showing anything.

Please help to resolve this problem.

Upvotes: 0

Views: 2969

Answers (1)

rkosegi
rkosegi

Reputation: 14618

Error you posted is related to linker.Did you include libmysql.lib or mysqlcppconn.lib as additional library in your project?

you can also try

#pragma comment(lib,"libmysql.lib")

or

#pragma comment(lib,"mysqlcppconn.lib")

Be sure that lib file is in configured library directory

Upvotes: 1

Related Questions