java—无法从eclipse中的jsp连接到mysql数据库

c9qzyr3d  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(401)

我试图在eclipse中从jsp连接到db,以便构建一个webite。我知道通过.java文件可以很好地进行连接。我已经添加了mysql连接器和所有东西,但是我不明白为什么它不能连接。这是我的密码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login page</title>
</head>
<body>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>

<%

    Connection con=null;

    try{
        Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection("jdbc:mysql://localhost/e-health?useSSL=false","root","root");
        System.out.println("Connection successful");
        out.println("Connection successful");
    }
    catch(Exception e){
        System.out.println("Connection failed");
    }

    out.println("Loged in, connected to the DB");
%>
<a href = "welcome.html">Welcome</a><br>
<a href= "index.html">Home</a>
</body>
</html>
sd2nnvve

sd2nnvve1#

导入程序顶部的包

<%@page import="java.sql.DriverManager"%>
<%@page import="com.mysql.jdbc.Connection"%>

相关问题