C ++ database connection to connect the MySQL database correctly

Source: Internet
Author: User
Tags informix interbase sybase

The following articles mainly describe the use of C ++ database connection to Oracle database, ms SQL, and the actual operation process of MySQL database, I recently found SQLAPI ++ on the Internet. Its main function is to access multiple sqldatabase Oracle (large website database platform ).

SQLServer, DB2, Sybase, Informix, InterBase, SQLBase, MySQL database PostgreSQL) C ++ library. SQLAPI ++ directly calls the DBMS of the local target database management system). Unlike ADO, the APIs use the OLEDBand/orODBC Middle Layer ).

The SQLAPI ++ Library plays the role of middleware for indirect and convenient access to the database, which is why SQLAPI ++ is the fastest way to access the database. You do not need to install or configure the OLEDBand/orODBC driver when developing and publishing your applications.

SQLAPI supports MicrosoftVisualC ++, BorlandC ++ Builder, and GunProjectCandC ++ Compiler.

The sample code is as follows:

 
 
  1. #include<stdio.h> forprintf  
  2. #include<SQLAPI.h>mainSQLAPI++header  
  3. intmain(intargc,char*argv[])  
  4. {  
  5. SAConnectioncon; 

Connect Data Objects

 
 
  1. SACommandcmd(  
  2. &con,  
  3. "Selectfid,fvarchar20fromtest_tbl");  

Command object, which contains a query statement. You can modify it as needed during testing.

Try

{

Connect to the MySQL database

In this routine, the database is connected to the Oracle (large website database platform) database,

Of course, it can also connect to Sybase, Informix, DB2

SQLServer, InterBase, SQLBaseandODBC

Con. Connect ("test", "tester", "tester", SA_Oracle (large website database platform) _ Client );

Execute the query statement

Cmd. Execute ();

Display query results

 
 
  1. while(cmd.FetchNext())  
  2. {  
  3. printf("Rowfetched:fid=%ld,fvarchar20='%s' ",  
  4. cmd.Field("fid").asLong(),  
  5. (constchar*)cmd.Field("fvarchar20").asString());  
  6. }  

Submit current transaction

 
 
  1. con.Commit();  
  2. printf("Rowsselected! ");  
  3. }  
  4. catch(SAException&x)  

Exception Handling

 
 
  1. try  

Exit current transaction

 
 
  1. con.Rollback();  
  2. }  
  3. catch(SAException&)  
  4. {  

Show error message

 
 
  1. printf("%s ",(constchar*)x.ErrText());  
  2. }  
  3. return0;  
  4. }  

The official website of SQLAPI ++ is www.sqlapi.com. It provides an evaluation version for the customer to test. Unfortunately, after the database file of the evaluated version is successfully connected to the database, a MessageBox dialog box will pop up. When I tested it, I got bored and cracked it. If necessary, I could download www.szsmart.net from my personal website, but only provided the cracked version of BCB.

The above content is to use C ++ database to connect to Oracle, ms SQL, MySQL database description, hope to bring you some help in this regard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.