当前位置: 代码迷 >> Java Web开发 >> jsp tomcat 连接mysql数据库遇到了有关问题!
  详细解决方案

jsp tomcat 连接mysql数据库遇到了有关问题!

热度:95   发布时间:2016-04-16 22:23:55.0
jsp tomcat 连接mysql数据库遇到了问题!!!
tomcat安装成功,数据库也建立成功

在浏览器中输入http://127.0.0.1:8080/myapp/first.jsp后出现如下提示
HTTP Status 500 - javax.servlet.ServletExceptionjava.sql.SQLException: Access denied for user 'soft'@'localhost' (using password: YES)

type Exception report

message javax.servlet.ServletException: java.sql.SQLException: Access denied for user 'soft'@'localhost' (using password: YES)

description The server encountered an internal error that prevented it from fulfilling this request.

这个改怎么解决!!!!???

jsp代码如下
<%@ page contentType="text/html;charset=gb2312"%> 
<%@ page import="java.sql.*"%> 
<html> 
<body> 
<%Class.forName("org.gjt.mm.mysql.Driver").newInstance(); 
String url ="jdbc:mysql://localhost/softforum?user=soft&password=soft1234&useUnicode=true&characterEncoding=8859_1";
//first为你的数据库名 
Connection conn= DriverManager.getConnection(url); 
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
String sql="select * from first"; 
ResultSet rs=stmt.executeQuery(sql); 
while(rs.next()) {%> 
您的第一个字段内容为:<%=rs.getString(1)%> 
您的第二个字段内容为:<%=rs.getString(2)%> 
<%}%> 
<%out.print("数据库操作成功,恭喜你");%> 
<%rs.close(); 
stmt.close(); 
conn.close(); 
%> 
</body> 
</html>


------解决方案--------------------
你用个工具登看看 用户名,密码对不
------解决方案--------------------
数据库连接错误,
检查是否导入jar包(java连接数据库 用的)之后,检查你的用户名和密码是否正确。
还有 你的mysql 服务是否已经开启!
  相关解决方案