用maven下吧!很好的管理工具,配置一下,就自动下载了
mysql的配置是
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
或者从这儿下
https://repository.sonatype.org/content/groups/public/mysql/mysql-connector-java/l
2.在mysql 的官方网站上找 Connector/J 关键字,然后点击download 就能下载到mysql 的jdbc支持包
Connector/J
(Current Generally Available Release: 5.1.21)Standardized database driver for Java platforms and development.
Download
在mysql 的官方网站上找 Connector/J 关键字,然后点击download 就能下载到mysql 的jdbc支持包Connector/J
(Current Generally Available Release: 5.1.21)Standardized database driver for Java platforms and development.
Download
import java.sql.Connection
import java.sql.DriverManager
//数据库连接测试
public class TestConnection {
public static void main(String[] args) {
try {
//加载驱动
Class.forName("com.mysql.jdbc.Driver")
//“127.0.0.1:3306/e1101"你懂的
String url = "jdbc:mysql://127.0.0.1:3306/e1101"
//通过DriverManager获取连接“root”是你的mysql安装时的账号和密码
Connection conn = DriverManager.getConnection(url,"root","root")
System.out.println("conn: " + conn)
} catch (Exception e) {
e.printStackTrace()
}
}
}
你去试一下
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)