Java连接MYSQL数据库
MySQL
下载地址:https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-winx64.zip
文件名:mysql-5.7.19-winx64.zip
安装:直接双击EXE就可以安装。

端口:3306
密码:zhujq
服务名:MySQLPC

JDBC

下载地址:https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.44.zip

备用下载地址:http://mirrors.myxw.ml/attached/mysqljdbc.zip

文件名:mysql-connector-java-5.1.44.zip
安装:
1.解压到“D:RuanjianJavamysql-connector-java-5.1.44”下面。
2.将“mysql-connector-java-5.1.44-bin.jar”复制到“D:Ruanjianapache-tomcat-8.5.14lib”下面。
3.“MyJSP”项目上右击->“Properties”->“java Build Path”->“Libraries”->“Add External JARs...”->
选择“D:Ruanjianapache-tomcat-8.5.14libmysql-connector-java-5.1.44-bin.jar”->“OK”。
4.重新启动“D:Ruanjianapache-tomcat-8.5.14binstartup.bat”


连接实例:

try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		try {
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/world","root", "123456");
			Statement smt = con.createStatement();
			ResultSet rs= smt.executeQuery("select * from country;");
			System.out.println(rs);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

发表评论

表情(⊙o⊙)…
看不清楚?点图切换 Ctrl+Enter快速提交

网友评论(0)

sitemap