메뉴 건너뛰기

tnt_lang

/**
* 프리페어스테이트먼트에  ? 표 자리에 값을 셋팅후 만들어진 SQL 문을 보는 유틸
*
*
* @원작자 : 정영환 2001.02.27   jyhwan@dreamwiz.com
* @수정자 : 워니   2001.10.19   nawon2000@hanmail.net
*/

package kr.co.gooper.buy.util;

import java.util.*;
/*
Usage :  String query="insert into tablename set(xxx,yyy) values(?,?)"
         PreparedStatementPrinter pstmtp = new PreparedStatementPrinter();
         pstmtp.setString(1,"12345");
         pstmtp.setInt(1,12345);
         System.out.println(psp.toString(query));
*/

public class PreparedStatementPrinter {

   Vector v = new Vector();
  

   public void setString(int i,String param) {
      v.addElement((String)("'" + param + "'"));
   }

   public void setDouble (int i,double param) {
      v.addElement(new Double(param));
   }

   public void setFloat (int i,float param) {
      v.addElement(new Float(param));
   }

   public void setInt (int i,int param) {
      v.addElement(new Integer(param));
   }

   public void setLong (int i,long param) {
      v.addElement(new Long(param));
   }

   public String toString(String sqlStr) {

      int seq = 0;
      StringBuffer buf = new StringBuffer();

      for(int i; (i = sqlStr.indexOf("?")) >= 0; ) {
         buf.append(sqlStr.substring(0,i));
         buf.append((v.elementAt(seq)).toString());
         sqlStr = sqlStr.substring(i + "?".length());
         seq++;
      }
      buf.append(sqlStr);
      return buf.toString();
   }
}

위로