jdbc连接数据库,后台报
java.net.ConnectException时,怎样在jsp前台显示错误信息
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;
}
------解决方案--------------------自己写个
自定义异常