在Eclipse中将MySQL SQL Server Management Studio连接到JSP项目

时间:2019-07-18 14:24:25

标签: mysql jsp

我尝试使用jsp将mysql连接到eclipse。

我已添加mysql连接器,并将其复制到web-inf/lib 并且运行了wamp服务器,但显示以下内容:

Unable to connect to databasejava.lang.ClassNotFoundException: com.mysql.jdbc.Driver 

代码是:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ page import ="java.sql.*" %>

<%
try {
  String connectionURL = "jdbc:mysql://localhost/3306/movie_booking";
  Connection connection =null; 
  Class.forName("com.mysql.jdbc.Driver").newInstance(); 
  connection = DriverManager.getConnection(connectionURL, "root", "");
  if(!connection.isClosed())
    out.println("Successfully connected to " + "MySQL server using TCP/IP...");
  connection.close();
}catch(Exception ex){
  out.println("Unable to connect to database"+ex);
}       
%>
</body>
</html>

0 个答案:

没有答案