Home > Database > Mysql Tutorial > Java连接mysql的方法_MySQL

Java连接mysql的方法_MySQL

WBOY
Release: 2016-05-31 08:48:33
Original
1186 people have browsed it

Error : java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
问题原因:java开发环境中没有加载mysql数据库的驱动程序
解决方案:
下载mysql支持的驱动程序:http://dev.mysql.com/downloads/connector/j/
下载后直接安装,然后在 mysql 的安装目录里面会有  Connector J 5.1.30  相应版本的文件夹,里面有 mysql-connector-java-5.1.30-bin.jar,正是驱动文件。点击java的项目名称,在 ecplise 里面,依次点击    java项目名称——  build path  ——  configure build path  ——   Add External JARS,然后把mysql-connector-java-5.1.30-bin.jar文件引进来就行了。
下面是连接测试代码:
其中 URL=协议名+IP地址(域名)+端口+数据库名称;用户名和密码是指登录数据库时所使用的用户名和密码。具体示例创建MySQL的数据库连接代码如下:
              Connection connectMySQL  =  DriverManager.geiConnection(“jdbc:mysql://localhost:3306/DataBase","root" ,"密码" );

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template