java MySQl数据库连接
时间:2021-07-01 10:21:17
帮助过:25人阅读
="java.sql.Connection" %>
<%@ page
import="java.sql.DriverManager" %>
<%@ page
import="java.sql.SQLException" %>
<%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2019/8/14
Time: 11:25
To change this template use File | Settings |
File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>测试</title>
</head>
<body>
<%
try {
String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver"
;
String DB_URL = "jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC"
;
Class.forName(JDBC_DRIVER);
String userName="root"
;
String userPwd="123456"
;
Connection conn=
DriverManager.getConnection(DB_URL,userName,userPwd);
if(conn!=
null){
out.println("数据库连接成功!"
);
conn.close();
}else {
out.println("数据库连接失败!"
);
}
}catch (ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
%>
</body>
</html>
java MySQl数据库连接
标签:pwd file intel ext idea time har for title