我在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的问题,还是我这边的问题啊?求高手赐教,感激不尽。

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐