Correct I noticed Debian isn't on that list, but in most cases it will run either way. Ubuntu and Debian can run together, from my experience. :)
I will try that, thanks! :)
Printable View
Correct I noticed Debian isn't on that list, but in most cases it will run either way. Ubuntu and Debian can run together, from my experience. :)
I will try that, thanks! :)
Okay some updates.
I can now compile it and it compiles, but:
But then I want to execute my hw file.Code:g++ hw.cpp -o ./hw -lmysqlcppconn
/usr/bin/ld: warning: libstdc++.so.5, needed by /usr/local/lib/libmysqlcppconn.so, may conflict with libstdc++.so.6
It compiles now, but surely it does not work :(Code:./hw
Aborted
How am I supposed to get around that? :S
Howdy RealChamp. At this link [link]http://blog.ulf-wendel.de/?p=215[/link] about two thirds down the page there's a bit that says. On this post they are using Visual Studio. But still if both of those libraries are needed in that for that compiler then maybe you'll also need it. I wouldn't be surprised if i was way off. I'm just reading as much as I can on C++ and everything actually on this website; and figured it was worth taking a look into.Code:As said, you need to link both "mysqlcppconn-static.lib" and "libmysql.lib". Add both to the list of additional dependencies.
Thanks alot! I linked the mysqlcppconn-static to the project too(on Debian, still).
Tell me if I'm compiling it wrong, because I do not know. Also I've changed abit in the code, but this run error annoyes me(the terminate called after throwing an instance of 'sql::InvalidARgumentException')Code:# g++ hw.cpp -o hw -lmysqlcppconn-static -lmysqlcppconn
/usr/bin/ld: warning: libstdc++.so.5, needed by /usr/local/lib/libmysqlcppconn.so, may conflict with libstdc++.so.6
# ./hw
terminate called after throwing an instance of 'sql::InvalidArgumentException'
what(): You should not call directly the constructor
Aborted
New code:
Been on Google to find a result for my problem, but it's not really the same I think.Code:#include <iostream>
#include <stdlib.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>
int main(){
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
try{
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
con->setSchema("test");
stmt = con->createStatement();
stmt->execute("insert into example values(4,'four'),(5, 'five')");
delete stmt;
pstmt = con->prepareStatement("select * from example");
res = pstmt->executeQuery();
while (res->next())
std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl;
delete res;
delete pstmt;
pstmt = con->prepareStatement("delete from example where id=?");
pstmt->setInt(1,4);
pstmt->executeUpdate();
pstmt->setInt(1,5);
pstmt->executeUpdate();
delete pstmt;
delete con;
}catch(sql::SQLException &e){
std::cout<<e.what();
}
}
It's something about memory, but I doubt that's the problem :)
Before you do anything else, are you using a debugger?
That exception is being thrown because one of those calls you're making caused the error, but you failed to mention at all which one of those lines is throwing the exception. This gives the impression that you're not using a debugger. You seem to be writing code and hoping something works, which is not the way a programmer is supposed to approach writing something such as you're doing.
You don't need Google searches -- what you need to do is identify the line that is causing the problem, and from there either debug into the library, or read the library documentation carefully to make sure you are doing things correctly.
Secondly, I don't know about the particular API you're using, but it is bad design to blindly call "delete" like that, unless it is documented that you must do this to release the memory. Usually the API takes care of the cleanup automatically, or the API gives you a function that you call to clean up the resources yourself.
If you supposed to call delete, then RAII certainly isn't high on this particular C++ wrapper's list, which is a shame.
Regards,
Paul McKenzie
Thanks for reply. I was not given a specific line where the error is from. But I will go check the documentation for a debug compiler, thanks!
Okay I've installed the g++ Debug. (apt-get install gdb) and compiled my program with an adionnally paramenter(-g).
Could not open /proc/25899/status seems to be the problem and that is ... something about stats..Code:This GDB was configured as "x86_64-linux-gnu"...
(gdb) run
Starting program: hw
[Thread debugging using libthread_db enabled]
Could not open /proc/25899/status
I've set a breakpoint at the initailization of the program(about line 1) and it throws me that error or incase I skip to the next error it's just something about a function..(Cannot find bounds of current function).
This line is the problem.
Code:driver = get_driver_instance();
Just for fun I would try also linking libmysql.lib if I knew how.
I suggest resorting to the old technique of putting printf()'s or couts to really see how far your program goes before it throws the exception:
So if the debugger is giving you a problem, at least you have that technique as a poor-mans debugger.Code:printf("I am at point 1\n");
some SQL code...
printf("I am at point 2\n");
some SQL code...
etc...
Secondly, if that line is the one that is actually throwing an exception, then I would conclude there is something wrong with the build, as that is the initialization function and nothing else needs to be done to call it.
Many times, library code just bombing out at the very function call indicates a build problem of the library (wrong build, bad build, etc.), or your own code is being built with the wrong switches used (more likely the latter if that library was already built for you). If you build your app with the wrong switches, improper constants, structs, etc. would be used by your app, differing what is in the library code. Yes, you get a build, but the build is a big mess where the same struct, class, etc. is defined differently in two places, causing random crashes.
Check that you built your code with the correct switches.
Regards,
Paul McKenzie
I hope you're not having that big mess that Paul said might be happening. I would go nuts if that was happening to me. I found this article usefull for me by the way in case you would be interested in it: http://dev.mysql.com/tech-resources/...ector-cpp.html