java MySQl数据库连接

<%@ page import="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?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>

 

posted @ 2019-08-14 15:56  青春-无悔  阅读(140)  评论(0编辑  收藏  举报