我在jsp页面中插入以下语句,为什么会出错呢?
错误如下:
javax.servlet.ServletException: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
<%
String str = "";
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:10100/dabc98d7befac43df8d0bc7d69577718e" +
"?useUnicode=true&characterEncoding=gb2312&autoReconnect=true&failOverReadOnly=false";
Connection con= DriverManager.getConnection(url,"u7T3cy8R52Xun","pWJpeuwrSiChH");
Statement smt=con.createStatement();
String sql = "select * from admins";
ResultSet rs = smt.executeQuery(sql);
while(rs.next())
{
str = rs.getString(1);
out.print(str);
}
%>
但是在java文件中直接执行下列语句没问题啊.
String str = "";
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:10100/dabc98d7befac43df8d0bc7d69577718e" +
"?useUnicode=true&characterEncoding=gb2312&autoReconnect=true&failOverReadOnly=false";
Connection con= DriverManager.getConnection(url,"u7T3cy8R52Xun","pWJpeuwrSiChH");
Statement smt=con.createStatement();
String sql = "select * from admins";
ResultSet rs = smt.executeQuery(sql);
while(rs.next())
{
str = rs.getString(1);
System.out,print(str);
}
这是为什么呢?是CloudFoundry的问题,还是我这边的问题啊?求高手赐教,感激不尽。
因为你的url pwd name写死了……是要获取动态的,虽然你创建service复制下来的是这些数据。
JSONObject credentials = new JSONObject(VCAP_SERVICES) .getJSONArray("mysql-5.1").getJSONObject(0).getJSONObject("credentials");
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。