package printSqlException;
import java.sql.SQLException;
import java.util.Calendar;
/*
* 类名:PintSqlException
* 类说明:通过打印方法,直接打印出SQLException中的警告及错误信息
* 作者:王康宇
* 日期:2007-03-15
*/
public class PrintSqlException {
SQLException se;
Calendar rn=Calendar.getInstance();
public PrintSqlException(SQLException se)
{
this.se=se;
}
public boolean printWarning() throws SQLException
{
Boolean rs=false;
if (se!=null)
{
rs=true;
System.out.println("/n**********Warning Start********"+rn.getTime()+"/n");
while(se!=null)
{
System.out.println("SQLState:"+se.getSQLState());
System.out.println("WarningMessage:"+se.getMessage());
System.out.println("Vendor:"+se.getErrorCode());
System.out.println("");
se=se.getNextException();
}
System.out.println("/n**********Warning End********"+rn.getTime()+"/n");
}
return rs;
}
public boolean printException()
{
boolean rs=false;
if (se!=null){
rs=true;
System.out.println("*******SQLException"+rn.getTime());
while (se!=null)
{
System.out.println("Message:"+se.getMessage());
se=se.getNextException();
}
}
return rs;
}
}
import java.sql.SQLException;
import java.util.Calendar;
/*
* 类名:PintSqlException
* 类说明:通过打印方法,直接打印出SQLException中的警告及错误信息
* 作者:王康宇
* 日期:2007-03-15
*/
public class PrintSqlException {
SQLException se;
Calendar rn=Calendar.getInstance();
public PrintSqlException(SQLException se)
{
this.se=se;
}
public boolean printWarning() throws SQLException
{
Boolean rs=false;
if (se!=null)
{
rs=true;
System.out.println("/n**********Warning Start********"+rn.getTime()+"/n");
while(se!=null)
{
System.out.println("SQLState:"+se.getSQLState());
System.out.println("WarningMessage:"+se.getMessage());
System.out.println("Vendor:"+se.getErrorCode());
System.out.println("");
se=se.getNextException();
}
System.out.println("/n**********Warning End********"+rn.getTime()+"/n");
}
return rs;
}
public boolean printException()
{
boolean rs=false;
if (se!=null){
rs=true;
System.out.println("*******SQLException"+rn.getTime());
while (se!=null)
{
System.out.println("Message:"+se.getMessage());
se=se.getNextException();
}
}
return rs;
}
}
本文介绍了一个用于打印SQL异常和警告信息的Java工具类。该工具类可以详细展示SQL执行过程中出现的问题,包括SQL状态、警告消息及供应商错误码等。
2万+

被折叠的 条评论
为什么被折叠?



