#include#include ODBCConnection conn("myserver", "mydatabase", "username", "password"); SqlStatement stmt(conn); stmt.Execute( "CREATE TABLE customers (" " id INT PRIMARY KEY," " name VARCHAR(50)," " email VARCHAR(50)," " phone VARCHAR(15)" ");" );
#includeIn this example, an ODBCConnection object is created to connect to a server and database using a username and password. Then, a SqlStatement object is created with the connection. Finally, the Execute method is called on the SqlStatement object with an SQL statement to select the name and email columns from the "customers" table where the id is equal to 1. The Fetch method is called in a loop to retrieve each row of data, and the GetString method is used to get the values of the name and email columns as strings. These values are then printed to the console. Package library: ODBC (Open Database Connectivity)#include ODBCConnection conn("myserver", "mydatabase", "username", "password"); SqlStatement stmt(conn); stmt.Execute("SELECT name, email FROM customers WHERE id=1"); while (stmt.Fetch()) { std::string name = stmt.GetString("name"); std::string email = stmt.GetString("email"); std::cout << "Name: " << name << " Email: " << email << std::endl; }