首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Exception >

java.net.ConnectException MESSAGE: Connection refused: connect

2014-01-26 
String url jdbc:mysql://localhost/tableName?useranan&password123456&useUnicodetrue&characterEn

String url = "jdbc:mysql://localhost/tableName?user=anan&password=123456&useUnicode=true&characterEncoding=8859_1 "; Class.forName( "com.mysql.jdbc.Driver ");
conn = DriverManager.getConnection(url);

当数据库未启动时,此时后台会报java.net.ConnectException MESSAGE: Connection refused: connect。但前台jsp页面确正常,只是没有结果记录显示,
这样很不直观,请问如何让后台的报错信息同时也在前台显示

------解决方法--------------------------------------------------------
做个异常处理在前台输出不就行拉!
out.println(e.toString());
------解决方法--------------------------------------------------------
try{
String url = "jdbc:mysql://localhost/tableName?user=anan&password=123456&useUnicode=true&characterEncoding=8859_1 "; Class.forName( "com.mysql.jdbc.Driver ");
conn = DriverManager.getConnection(url);
}
catch(Exception e)
{ out.print(e.getMessage());}
------解决方法--------------------------------------------------------
try{
String url = "jdbc:mysql://localhost/tableName?user=anan&password=123456&useUnicode=true&characterEncoding=8859_1 ";Class.forName( "com.mysql.jdbc.Driver ");
conn = DriverManager.getConnection(url);
}
catch(Exception e)
{ request.setAttribute( "ex ",e.getMessage().toString());
return forward;
}
------解决方法--------------------------------------------------------
自己写个自定义异常

        

热点排行