如何在eclipse中添加mysql驱动程序jar文件 [英] how to add mysql driver jar file in eclipse

查看:809
本文介绍了如何在eclipse中添加mysql驱动程序jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有jar文件: mysql-connector-java-5.1.14-bin.jar 我想将它添加到我的项目中。
我以这种方式添加jar:project-> properties - >(Java Build Path)库并从外部jar添加它。但是当我尝试使用它并写:



import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;



import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;



我在com.mysql下收到错误。



我的错误是什么?





那么你不需要一个 import 语句。只需使用 DriverManager.getConnection(),Java应该能够找到JDBC驱动程序。

  String myConnectionString = 
jdbc:mysql:// localhost:3307? +
useUnicode = yes& characterEncoding = UTF-8;
//以下语句假设
// import java.sql。*;
连接dbConnection = DriverManager.getConnection(myConnectionString,root,myPassword);


I have the jar file: mysql-connector-java-5.1.14-bin.jar and I want to add it to my project. I add the jar at this way: project-> properties -> (Java Build Path) Libraries and add it from external jars. But when I try to use it and write:

import com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

I get error under "com.mysql".

What is my mistake?

解决方案

If the JAR file for the JDBC driver appears in the "Referenced Libraries" branch of the project, like this:

then you don't need an import statement for it. Just use DriverManager.getConnection() and Java should be able to find the JDBC driver itself.

String myConnectionString =
        "jdbc:mysql://localhost:3307?" +
        "useUnicode=yes&characterEncoding=UTF-8";
// the following statement assumes
//     import java.sql.*;
Connection dbConnection = DriverManager.getConnection(myConnectionString, "root", "myPassword");

这篇关于如何在eclipse中添加mysql驱动程序jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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