作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 MYSQL 和 JSP 的新手。我正在尝试检查 mysql 数据库和 jsp 之间的连接。当我在服务器上运行该项目时,它抛出异常。我找不到代码上的错误。
我在mysql上创建了oop数据库,UN、PW也都是正确的。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Connection status </h1>
<%
/* Create string of connection url within specified format with machine name,
port number and database name. Here machine name id localhost and
database name is oop. */
String connectionURL = "jdbc:mysql://localhost:3306/oop";
// declare a connection by using Connection interface
Connection connection = null;
// Load JBBC driver "com.mysql.jdbc.Driver"
Class.forName("com.mysql.jdbc.Driver").getDeclaredConstructors();
/* Create a connection by using getConnection() method that takes parameters of
string type connection url, user name and password to connect to database. */
connection = DriverManager.getConnection(connectionURL, "root", "raviya");
// check weather connection is established or not by isClosed() method
if(!connection.isClosed()){
%>
<font size="+3" color="green">
<%
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}
else{
%>
</font>
<font size="+3" color="red">
<%
out.println("Unable to connect to database.");
}
%>
</font>
</body>
</html>
最佳答案
如果您没有导入 mysql 连接器 jar 文件,可能会发生此类错误。因此,您可以下载与您的版本相关的jar文件并将其粘贴到您自己的项目/WEB-INF/lib文件夹中。
关于mysql - 如何修复 "DriverManager.getConnection(connectionURL, UN, PW); "上的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55800484/
我在 AWS 上设置了一个 MongoDB 实例,并尝试从安装了我的 Web 应用程序的另一个 AWS 实例连接到它。 以下是我的 jdoconfig.xml 文件的内容:
hive-site.xml 中的以下属性对于 Hive 访问 cassandra 是否正确? (我复制了整个 HIVE-DEFAULT.XML 内容,但仅更改了以下属性) javax.jdo.opti
我是 MYSQL 和 JSP 的新手。我正在尝试检查 mysql 数据库和 jsp 之间的连接。当我在服务器上运行该项目时,它抛出异常。我找不到代码上的错误。 我在mysql上创建了oop数据库,UN
我是一名优秀的程序员,十分优秀!