简体   繁体   中英

Cannot connect to mySQL DB from jsp in Eclipse

I am trying to connect to a DB from jsp in eclipse , in order to build a webite. I know the connection works fine from a .java file. I have the mysql connector added and everything, but I can't figure out why it won't connect. Here is my code:

<%@ 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>

Import the packages at the top of the program

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM