Hi all members
I'm a learning how to use C/C++ on Netbeans IDE. I got an tutorial on net I am trying this tutorial to complete since last 5 days---
I followed the tutorial step by step.
My system settings -
Window 7 32 bits
Netbeans 7.1
JDK 1.7
cygwin 1.7.17-1
gcc 3.4.4
g++ 3.4.4
make 3.82.90
gdb 7.5.50
mysql Connector C++ 1.0.5
XAMPP
mysql server 5.5.16
I included header files path and library file path as shown in image I attached for clear picture.

This the code I just want to check whether database is connected correctly or not.
This the code which I gor from net-

#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>

/* MySQL Connector/C++ specific headers */
#include <driver.h>
#include <connection.h>
#include <statement.h>
#include <prepared_statement.h>
#include <resultset.h>
#include <metadata.h>
#include <resultset_metadata.h>
#include <exception.h>
#include <warning.h>
#include <mysql_driver.h>

#define DBHOST "localhost:3306"
#define USER "root"
#define PASSWORD ""
#define DATABASE "bill"

#define NUMOFFSET 100
#define COLNAME 200

using namespace std;
using namespace sql;

int main(int argc, char** argv) {
    Driver *driver;
    Connection *con;
    Statement *stmt;
    ResultSet *res;
    PreparedStatement *prep_stmt;
    Savepoint *savept;

    int updatecount = 0;
    string url(argc >= 2 ? argv[1] : DBHOST);
    const string user(argc >= 3 ? argv[2] : USER);
    const string password(argc >= 4 ? argv[3] : PASSWORD);
    const string database(argc >= 5 ? argv[4] : DATABASE);
    try {
          driver = get_driver_instance();
          con = driver -> connect(url, user, password);
          cout<<"Successfull";
          delete res;
          delete stmt;
          delete prep_stmt;
          con -> close();
          delete con;
        }
        catch (SQLException &e) {
    cout << "ERROR: SQLException in " << __FILE__;
    cout << " (" << __func__<< ") on line " << __LINE__ << endl;
    cout << "ERROR: " << e.what();
    cout << " (MySQL error code: " << e.getErrorCode();
    cout << ", SQLState: " << e.getSQLState() << ")" << endl;
    if (e.getErrorCode() == 1047) {
        cout << "\nYour server does not seem to support Prepared Statements at all. ";
        cout << "Perhaps MYSQL < 4.1?" << endl;
    }
    return EXIT_FAILURE;
    } catch (std::runtime_error &e) {
        cout << "ERROR: runtime_error in " << __FILE__;
        cout << " (" << __func__ << ") on line " << __LINE__ << endl;
        cout << "ERROR: " << e.what() << endl;

        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;  
    return 0;
}

After doing all these and finally I do Build Project
Netbeans not confirm who may be cygwin compiler shows these lines

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/cygdrive/c/Users/Vishal/Documents/NetBeansProjects/CppApplication_1'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin-Windows/cppapplication_1.exe
make[2]: Entering directory `/cygdrive/c/Users/Vishal/Documents/NetBeansProjects/CppApplication_1'
mkdir -p dist/Debug/Cygwin-Windows
g++.exe     -o dist/Debug/Cygwin-Windows/cppapplication_1 build/Debug/Cygwin-Windows/main.o -L/cygdrive/C/Program\ Files/MySQL/MySQL\ Connector\ C++\ 1.0.5/lib/opt 
build/Debug/Cygwin-Windows/main.o: In function `main':
/cygdrive/c/Users/Vishal/Documents/NetBeansProjects/CppApplication_1/main.cpp:52: undefined reference to `_get_driver_instance'
collect2: ld returned 1 exit status
make[2]: *** [dist/Debug/Cygwin-Windows/cppapplication_1.exe] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-Debug.mk:61: recipe for target `dist/Debug/Cygwin-Windows/cppapplication_1.exe' failed
make[2]: Leaving directory `/cygdrive/c/Users/Vishal/Documents/NetBeansProjects/CppApplication_1'
nbproject/Makefile-Debug.mk:58: recipe for target `.build-conf' failed
make[1]: Leaving directory `/cygdrive/c/Users/Vishal/Documents/NetBeansProjects/CppApplication_1'
nbproject/Makefile-impl.mk:39: recipe for target `.build-impl' failed

BUILD FAILED (exit value 2, total time: 3s)

After all research finally I came to Daniweb with expectation of any hekp

First off, for future reference, is is considered bad form to cross-post questions like this, as it can lead to a duplication of effort. In the future, I recommend posting to different forums one at a time, and only if you haven't gotten a response after at least four days post to another forum (and let the people on both forums know you are doing it).

Addressing the question itself, the problem appears to lie in the call to get_driver_instance() on line 44. In order to link in that function, you need to have the library mysqlcppconn-static as part of you build. I'm not entirely certain how you would do this under NetBeans, offhand, but in GCC in general, you woul add -l<name-of-library> to your g++ invocation (in this instance, it would be -lmysqlcppconn-static). If anyone here is more familiar with NetBeans, they may be able to advise you.

Edited 4 Years Ago by Schol-R-LEA

Thank you for your consideration.
But I hope you can understand my frustation, thats why I posted this issue first in netbeans forum 6 hours back, after not getting any reply from there, I posted here.

Any ways Thank you suggestion and guidance, but this will not solve my issue.
Regards

This article has been dead for over six months. Start a new discussion instead.