如何配置 MySQL JDBC 驱动程序 mysql-connector-java-5.1.12?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2907141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 14:22:06  来源:igfitidea点击:

How to configure MySQL JDBC driver mysql-connector-java-5.1.12?

javamysqlapache-flexjdbc

提问by Nithi

I have downloaded MySQL JDBC driver from http://www.mysql.com/downloads/connector/j/. How do I configure it?

我已经从http://www.mysql.com/downloads/connector/j/下载了 MySQL JDBC 驱动程序。我该如何配置?

回答by BalusC

To the point, you just need to put it in the program's runtime classpath and then load it as follows:

说到点子上,你只需要把它放在程序的运行时类路径中,然后按如下方式加载它:

try {
    Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
    throw new RuntimeException("Cannot find the driver in the classpath!", e);
}

If you're using an IDE, then you need to add the library to the project's Build Path. If you're running it using java.exe, then you need to specify the full path to the JDBC driver JAR file in the -cpargument, e.g. (Windows-targeted):

如果您使用的是 IDE,则需要将该库添加到项目的Build Path。如果您使用 运行它java.exe,那么您需要在参数中指定 JDBC 驱动程序 JAR 文件的完整路径-cp,例如(Windows 目标):

java -cp .;/path/to/mysql-connector-java-5.1.12.jar com.example.YourClass

For more information and hints check this small MySQL+JDBC kickoff tutorial.

有关更多信息和提示,请查看这个小型 MySQL+JDBC 启动教程

Update: As per the comments, you're using Flex and you apparently want to interact with the DB at the server using Flex. Well, Flex runs at the client machine and Java + the DB runs at the server machine. Both are connected by network with HTTP as communication protocol. You need to write Java code on the server side accordingly (Servlet? Webservice?) which interacts with the DB based on the parameters/pathinfo given with the HTTP request and returns the desired results. Then you can just invoke HTTP requests from inside Flex and process the HTTP response.

更新:根据评论,您正在使用 Flex,并且您显然希望使用 Flex 与服务器上的数据库进行交互。好吧,Flex 运行在客户端机器上,而 Java + DB 运行在服务器机器上。两者都通过网络连接,使用 HTTP 作为通信协议。您需要在服务器端相应地编写 Java 代码(Servlet?Webservice?),它根据 HTTP 请求给出的参数/路径信息与数据库交互并返回所需的结果。然后您可以从 Flex 内部调用 HTTP 请求并处理 HTTP 响应。

回答by Vaibhav Joshi

Refer < http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html> or

参考 < http://www.developer.com/java/data/jdbc-and-mysql-installation-and-preparation-of-mysql.html> 或

The JDBC .jar file needs to be added to the library, this can be done by adding it manually to '...jre\lib\ext' folder of your Java installation. It will be automatically included in the default library available to every project you create.

需要将 JDBC .jar 文件添加到库中,这可以通过将其手动添加到 Java 安装的“...jre\lib\ext”文件夹中来完成。它将自动包含在您创建的每个项目可用的默认库中。

回答by xYan

You can follow the guidelines given at: https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing.html. Also check the comments for more ideas and info. I.e: putting it in [PATH_TO_JAVA]/jre/lib/ext/(on Win Mashine) or /Library/Java/Extensions(Mac OS X) etc.

您可以遵循以下指南:https: //dev.mysql.com/doc/connector-j/5.1/en/connector-j-installing.html。另请查看评论以获取更多想法和信息。即:将其放入[PATH_TO_JAVA]/jre/lib/ext/(在 Win Mashine 上)或/Library/Java/Extensions(Mac OS X)等。