Exemplo n.º 1
0
void MultimediaCollection::addBorrower(Borrower b)
{
	borrowers.push_back(b);
	try {
		sql::Driver *driver;
		sql::Connection *con;
		sql::PreparedStatement *prepareStmt;

		driver = get_driver_instance();
		con = driver->connect("tcp://127.0.0.1:3306", "root", "dhis");
		con->setSchema("test");

		prepareStmt = con->prepareStatement(
			"INSERT INTO borrower(id, name, type, department, mobile, numborrow, numreturnlate)" 
			"VALUES (?,?,?,?,?,?,?)");
		prepareStmt->setString(1, b.getId());
		prepareStmt->setString(2, b.getName());
		prepareStmt->setString(3, b.getType());
		prepareStmt->setString(4, b.getDepartment());
		prepareStmt->setString(5, b.getMobile());
		prepareStmt->setInt(6, b.getNumItemBorrow());
		prepareStmt->setInt(7, b.getNumItemLateBorrow());

		prepareStmt->execute();

		delete prepareStmt;
		delete con;

	} catch (sql::SQLException &e) {
	  cout << "# ERR: SQLException in " << __FILE__;
	  cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
	  cout << "# ERR: " << e.what();
	  cout << " (MySQL error code: " << e.getErrorCode();
	  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
	}
}