关于JSP连接数据库出现的问题,望大神指点

啊啊啊啊柴 2017-12-20 09:34:16
首先我说一下出现的问题吧
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user ''@'localhost' (using password: YES))
................
Caused by: java.sql.SQLException: Access denied for user ''@'localhost' (using password: YES)
.................


然后这是我的连接池配置
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<WatchedResource>WEB-INF/web.xml</WatchedResource> <!-- 监听资源 -->
<Resource
name="jdbc/dataexam"
auto="Container"
type="javax.sql.DataSource"
driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc:mysql://localhost:3306/dataexam"
usename="root"
password="962432174"
MaxActive="5000"
maxIdle="10"
maxWait="-1"
></Resource>
</Context>

然后是测试代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="javax.naming.Context" %>
<%@ page import="javax.sql.DataSource" %>
<%@ page import="javax.naming.InitialContext" %>
<%@ page import="java.sql.*" %>
<%@ page import="myclass.dal.*" %>
<%@ page import="myclass.bol.*" %>
<%@ page import="java.util.ArrayList" %>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
1234
<%DBAcess dba = new DBAcess();
examineeDal examd=new examineeDal();
ArrayList<examinee> list =new ArrayList<examinee>();
try{
int rsult=
examd.CreateExaminee("123635673879","黄呵呵","女","江西师范大学","江西南昌","17379245533","kind@163.com","123456","中级","");
out.print(rsult);
dba.getConnection();
if(dba.getConn()!=null){
out.println("已经获得DataSourece");
out.println("<br>");
String str="select * from examinee";
ResultSet rst = dba.query(str);
out.println("一下是读取的数据<br>");
while(rst.next()){
out.println("<br>");
out.println(rst.getString(1));
}
out.println("系统时间:"+DBAcess.getSysDate());
examinee exambean = null;
exambean=examd.getExamineeByID("123635673879");
out.println("<br><br>"+exambean.getExamID());
list=examd.getExamineeAll();
for(examinee e:list){
out.println("<br>这个是死通过ArrayList得到的值:"+e.getExamID());
}
}
}catch(Exception ne){
out.println("出现如下错误:<br>");
out.println(ne);
}finally{
dba.closeConnection();
out.println("<br>已关闭DataSource!");
}
%>
</body>
</html>



运行结果无法返回数据库的数据,也就意味无法连接数据库
运行结果为:
1234 0
已关闭DataSource!
...全文
475 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
OwenZeng_DBA 2017-12-21
  • 打赏
  • 举报
回复
引用 2 楼 weixin_38423829 的回复:
感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件
1.检查下MySQL 是不是可以正常连接的 2.如果是远程访问你检查下,本机到mysql服务器的网络是否正常,端口是不是通的
nettman 2017-12-21
  • 打赏
  • 举报
回复
二月十六 2017-12-21
  • 打赏
  • 举报
回复
引用 2楼我是你的主体 的回复:
感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件
MySQL版本是什么,有default.ini吗?
OwenZeng_DBA 2017-12-21
  • 打赏
  • 举报
回复
@weixin_38423829 workbench 工具就可以连接远程的数据库啊,,你需要的远程连接是上面意思,是从这个mysql数据库连接到另外一个mysql数据库吗?
啊啊啊啊柴 2017-12-21
  • 打赏
  • 举报
回复
引用 10 楼 z10843087 的回复:
[quote=引用 7 楼 weixin_38423829 的回复:] [quote=引用 5 楼 z10843087 的回复:] [quote=引用 2 楼 weixin_38423829 的回复:] 感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件
1.检查下MySQL 是不是可以正常连接的 2.如果是远程访问你检查下,本机到mysql服务器的网络是否正常,端口是不是通的[/quote] 有没有通过mysql workbeach建立远程连接的方法,因为以前都是用sql server进行连接的所以对mysql操作还有些懵,望指点,谢谢大佬[/quote] 类似的,输入IP 端口 用户名和密码 [/quote] 我已经连接上数据库了,所以在workbeach中如何建立远程连接
OwenZeng_DBA 2017-12-21
  • 打赏
  • 举报
回复
引用 7 楼 weixin_38423829 的回复:
[quote=引用 5 楼 z10843087 的回复:]
[quote=引用 2 楼 weixin_38423829 的回复:]
感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件

1.检查下MySQL 是不是可以正常连接的 2.如果是远程访问你检查下,本机到mysql服务器的网络是否正常,端口是不是通的[/quote]
有没有通过mysql workbeach建立远程连接的方法,因为以前都是用sql server进行连接的所以对mysql操作还有些懵,望指点,谢谢大佬[/quote]
类似的,输入IP 端口 用户名和密码
二月十六 2017-12-21
  • 打赏
  • 举报
回复
恩我说的就是my-default.ini 把my-default.ini改成my.ini
啊啊啊啊柴 2017-12-21
  • 打赏
  • 举报
回复
引用 3 楼 sinat_28984567 的回复:
引用 2楼我是你的主体 的回复:
感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件
MySQL版本是什么,有default.ini吗?
weixin_38423829 weixin_38423829 T1 MySQL的版本是5.7没看到default.ini,但是有个my-default.ini文件里面的内容 # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
啊啊啊啊柴 2017-12-21
  • 打赏
  • 举报
回复
引用 5 楼 z10843087 的回复:
[quote=引用 2 楼 weixin_38423829 的回复:] 感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件
1.检查下MySQL 是不是可以正常连接的 2.如果是远程访问你检查下,本机到mysql服务器的网络是否正常,端口是不是通的[/quote] 有没有通过mysql workbeach建立远程连接的方法,因为以前都是用sql server进行连接的所以对mysql操作还有些懵,望指点,谢谢大佬
啊啊啊啊柴 2017-12-21
  • 打赏
  • 举报
回复
MySQL的版本是5.7没看到default.ini,但是有个my-default.ini文件里面的内容 # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html # *** DO NOT EDIT THIS FILE. It's a template which will be copied to the # *** default location during install, and will be replaced if you # *** upgrade to a newer version of MySQL. [mysqld] # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # These are commonly set, remove the # and set as required. # basedir = ..... # datadir = ..... # port = ..... # server_id = ..... # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
啊啊啊啊柴 2017-12-20
  • 打赏
  • 举报
回复
感谢大佬的回答,百度上的资料有点杂,也试了一些方法,都无法解决,你给我的连接里的方法,按理来说是可行的但是我的mysql目录下面没有my.ini文件
二月十六 2017-12-20
  • 打赏
  • 举报
回复
百度一下错误关键字很多资料 https://www.cnblogs.com/songyinan/p/6136025.html

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧