简体   繁体   English

从MySQL访问数据

[英]Accessing data from MySQL

I need to import data from an excel file into MySQL and then access the data and display it. 我需要将数据从Excel文件导入MySQL,然后访问数据并显示它。 Can someone give me an idea as to how i should go about this? 有人可以给我一个想法,我应该怎么做吗? Also can someone brief me about the hardware/software requirements (MySQL version to be installed) for this task? 还可以有人向我介绍此任务的硬件/软件要求 (要安装的MySQL版本)吗?

The question is quite broad. 这个问题很广泛。 Here are a few hints: 这里有一些提示:

  • Apache POI is a Java API for Microsoft Documents: with this you should be able to read your Excel file from Java Apache POI是用于Microsoft Documents的Java API:通过它,您应该能够从Java读取Excel文件

  • Then you can use JDBC to load your data to MySQL (assuming that you already have an appropriate database instance with table(s)). 然后,您可以使用JDBC将数据加载到MySQL(假设您已经具有带有表的适当数据库实例)。 A quick search on the Web will give you many examples such as this . 在网络上快速搜索会给你很多例子,如

I hope this helps! 我希望这有帮助!

http://blog.tjitjing.com/index.php/2008/02/import-excel-data-into-mysql-in-5-easy.html http://blog.tjitjing.com/index.php/2008/02/import-excel-data-into-mysql-in-5-easy.html

The above link explains how you can convert data from Excel and place it into a MySQL database. 上面的链接说明了如何从Excel转换数据并将其放入MySQL数据库。

http://dev.mysql.com/downloads/connector/j/ http://dev.mysql.com/downloads/connector/j/

As for your next question, you will then need to get the JDBC connect for MySQL (link above) from the website, and use it to connect to your database. 至于下一个问题,您将需要从网站上获取MySQL的JDBC连接(上面的链接),并使用它来连接数据库。

Once that is done, there are various methods you can use to retrieve data, and return it for use in your program! 完成之后,您可以使用多种方法来检索数据,并将其返回以供您在程序中使用!

It depends on how your data is structured and how often you want this done. 这取决于您的数据的结构方式和执行频率。

For a one time load and if you have something easy (eg 1 table) you can use string concatenation functions in excel to create the inserts. 对于一次加载,如果您有一些简单的操作(例如1个表),则可以在excel中使用字符串连接函数来创建插入。

If you have a more complex thing you can use a programming language to create the inserts. 如果您有更复杂的事情,可以使用编程语言来创建插入。 I am on UNIX and I favor PERL, I am converting the excel spreadsheets into CSV files (save as) and parse these in PERL. 我在UNIX上,我更喜欢PERL,我将excel电子表格转换为CSV文件(另存为),并在PERL中进行解析。 If you are on Windows you might have better programming options. 如果您使用Windows,则可能会有更好的编程选项。

Is this a testing/setup requirement or is it a business requirement that the application should be able to load data from excel files? 这是测试/设置要求还是业务要求,应用程序应该能够从excel文件加载数据?

In first case I would simply convert it to CSV and import the data using mysqlimport or use a GUI tool like SQLYog. 在第一种情况下,我将简单地将其转换为CSV并使用mysqlimport或使用SQLYog等GUI工具导入数据。 Software: SQLYog (Free Community Edition), mysqlimport (comes with MySQL) 软体:SQLYog(免费社区版),mysqlimport(MySQL随附)

In second case, I would use Apache POI. 在第二种情况下,我将使用Apache POI。 Software: Apache POI (Free and Open Source) 软体:Apache POI(免费和开放原始码)

BTW it is also possible to create a ODBC data source using a excel file. 顺便说一句,也可以使用Excel文件创建ODBC数据源。 You can use JDBC-ODBC bridge to access it. 您可以使用JDBC-ODBC桥来访问它。

Hardware: No special hardware requirement. 硬件:无特殊硬件要求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM