/*********************************************************************************************************
 * 프로그램명 : OPTSQLException.java 프로그램설명 : 각 서블릿 엔진에서 제공하는 전용 pool을 사용하기 위한 클래스 getConnection() 호출마다 서버 체크를 하지 않기 위해 현재
 * 환경만 비주석 처리해서 재컴파일하도록 한다.
 * 
 * 작성자 : 강원중 작성일 : 2003.12.16 변경일 : 2002.07.22
 **********************************************************************************************************/

package kr.co.kihyun.db;

import java.sql.*;

public class SQLMessage extends Throwable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	SQLException sqlEx = null;
	String formClass = null;
	String sql = null;

	public SQLMessage(SQLException sqlEx, String formClass, String sql) {
		this.sqlEx = sqlEx;
		this.formClass = formClass;
		this.sql = sql;
	}

	public SQLMessage(SQLException sqlEx, String sql) {
		this.sqlEx = sqlEx;
		this.sql = sql;
	}

	public SQLMessage(SQLException sqlEx) {
		this.sqlEx = sqlEx;
	}

	public String getMessage(String formClass) {
		StringBuffer strbuf = new StringBuffer();
		this.formClass = formClass;

		strbuf.append("\n\nSQLState: ");
		strbuf.append(sqlEx.getSQLState());
		strbuf.append("\nMySQL Error Code: ");
		strbuf.append(sqlEx.getErrorCode());
		strbuf.append("\nFile name: ");
		strbuf.append(formClass);
		strbuf.append("\nmessage: ");
		strbuf.append(sqlEx.getMessage());
		strbuf.append("\nsql: ");
		strbuf.append(sql);

		return strbuf.toString();
	}

	public static String getMessage(SQLException sqlEx, String formClass, String sql) {
		StringBuffer strbuf = new StringBuffer();

		strbuf.append("\n\nSQLState: ");
		strbuf.append(sqlEx.getSQLState());
		strbuf.append("\nMySQL Error Code: ");
		strbuf.append(sqlEx.getErrorCode());
		strbuf.append("\nFile name: ");
		strbuf.append(formClass);
		strbuf.append("\nmessage: ");
		strbuf.append(sqlEx.getMessage());
		strbuf.append("\nsql: ");
		strbuf.append(sql);

		return strbuf.toString();
	}

	public static String getMessage(SQLException sqlEx, String sql) {
		StringBuffer strbuf = new StringBuffer();

		strbuf.append("\n\nSQLState: ");
		strbuf.append(sqlEx.getSQLState());
		strbuf.append("\nMySQL Error Code: ");
		strbuf.append(sqlEx.getErrorCode());
		strbuf.append("\nmessage: ");
		strbuf.append(sqlEx.getMessage());
		strbuf.append("\nsql: ");
		strbuf.append(sql);

		return strbuf.toString();
	}

	public static String getMessage(SQLException sqlEx) {
		StringBuffer strbuf = new StringBuffer();

		strbuf.append("\n\nSQLState: ");
		strbuf.append(sqlEx.getSQLState());
		strbuf.append("\nMySQL Error Code: ");
		strbuf.append(sqlEx.getErrorCode());
		strbuf.append("\nmessage: ");
		strbuf.append(sqlEx.getMessage());

		return strbuf.toString();
	}
}
