如何使用odbc通过c++将excel文件导入到mysql表中?

发布于 2024-12-08 02:50:23 字数 127 浏览 0 评论 0原文

我有一个 C++ 程序,我计划使用 odbc 将我的 C++ 程序与 mysql 表进行通信。

网上有很多关于如何使用c++和odbc访问mysql表的教程,但是如何使用c++和odbc将excel文件加载到mysql表中?

I have a c++ program, and I am planning 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

命硬 2024-12-15 02:50:23

一种方法是将文件保存为 CSV,然后

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

在程序中执行以下语句。即如果您使用 C++ 包装器,

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

这应该可以工作。

如果您使用的是 C API,则使用

mysql_query(conn,<above query>)

另一种方法是通过 ODBC 连接连接到 Excel,从那里导入数据并导入到 MySQL。这个就比较复杂了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文