I have this c++ code that works fine, i can read from the tables and write to the tables: int main()
{ // Try to get a driver to use to connect to our DBMS try { driver = get_driver_instance(); } catch (sql::SQLException e) { cout << "Could not get a database driver. Error message: " << e.what() << endl; system("pause"); exit(1); } // Try to connect to the DBMS server try { dbConn = driver->connect(server, username, password); } catch (sql::SQLException e) { cout << "Could not connect to database. Error message: " << e.what() << endl; system("pause"); exit(1); } stmt = dbConn->createStatement(); // Specify which connection our SQL statement should be executed on // Try to query the database try { stmt->execute("USE test"); // Select which database to use. Notice that we use "execute" to perform a command. res = stmt->executeQuery("INSERT INTO users (fName, lName, age) VALUES ('fname', 'lname', 25)"); // Perform a query and get the results. Notice that we use "executeQuery" to get results back //res = stmt->executeQuery("SELECT * FROM users"); //return 0; } catch (sql::SQLException e) { cout << "SQL error. Error message: " << e.what() << endl; system("pause"); exit(1); } sql::ResultSetMetaData *res_meta = res -> getMetaData(); int columns = res_meta -> getColumnCount(); // While there are still results (i.e. rows/records) in our result set... while (res->next()) { for (int i = 1; i <= columns; i++) { cout << res->getString(i) << " | " ; } cout << endl; } delete res; delete stmt; delete dbConn; //system("pause"); return 0; }
So, this inserts to the table but then i get this error message
SQL error. Error message: sh: 1: pause: not found
This doesn’t happen if i use the > select .
Also i know that this question was already asked here but unfortunately it has no answer so i’m asking again.