如何配置MySQL JDBC驱动程序mysql-connector-java-5.1.12? [英] How to configure MySQL JDBC driver mysql-connector-java-5.1.12?

查看:421
本文介绍了如何配置MySQL JDBC驱动程序mysql-connector-java-5.1.12?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 http://www.mysql.com/downloads/下载了MySQL JDBC驱动程序连接器/ J / 。如何配置它?

解决方案

至此,您只需将其放入程序的运行时类路径中,然后加载它如下所示:

  try {
Class.forName(com.mysql.jdbc.Driver);
catch(ClassNotFoundException e){
throw new RuntimeException(无法在类路径中找到驱动程序!,e);



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

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

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

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


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

解决方案

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 -cp argument, e.g. (Windows-targeted):

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.

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.

这篇关于如何配置MySQL JDBC驱动程序mysql-connector-java-5.1.12?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆