开发者

How to use odbc to import excel file into mysql table via c++?

I have a c++ program, and I am pla开发者_Go百科nning to use odbc to communicate my c++ program with mysql tables.

There is alot of tutorials online on how to access mysql tables using c++ and odbc, but how do I use c++ and odbc to load a excel file into mysql tables?


One way is to save the file as a CSV and then execute the following statement

LOAD DATA LOCAL INFILE ‘C:\\temp\\yourfile.csv’ INTO 
TABLE database.table FIELDS TERMINATED BY ‘;’ 
ENCLOSED BY ‘”‘ LINES TERMINATED BY ‘\r\n’ (field1, field2);

in your program. i.e. if you are using the C++ wrapper,

stmt = con->createStatement();
stmt->execute(<above statement>);

This should work.

If you are using the C APIs then use

mysql_query(conn,<above query>)

The other way to do this would be to connect to Excel via an ODBC connection, import the data from there and import into MySQL. This is more complicated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜