DDL または DML コマンドを実行せずに JSP をデータベースに接続しようとしています。
これが私のJSPです:
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<html> <head> <title>Connection with mysql database</title>
</head>
<body>
<h1>Connection status</h1>
<%
try {
String connectionURL = "jdbc:mysql://localhost:3306/bharath";
Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
if(!connection.isClosed())
%>
<font size="+3" color="green"></b>
<%
out.println("Successfully connected to " + "MySQL server using TCP/IP...");
connection.close();
}
catch(Exception ex){
%></font>
<font size="+3" color="red"></b>
<%
out.println("Unable to connect to database.");
}
%>
</font></body> </html>
catch ブロックの例外が実行されます。では、try ブロックで何が問題になったのでしょうか。MySql をデフォルト設定でユーザーを"root"
、データベース名を としてインストールしまし"bharath"
た。
Exception -
java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4096) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4028) at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:919) at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1694) at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1244) at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2412) at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2445) at