JAKARTAPROJECT
JAKARTA TIPJSP TIPJSP Áú¹®&´äº¯DATABASE TIPJAVASCRIPT TIPWEBHACKING TIP±âŸ TIP
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ® ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
DBUtils¿¡¼­ number ŸÀÔÀÇ Ä÷³ÀÌ intÇüÀ¸·Î ¾È³Ñ¾î¿Ã¶§..
GoodBug
À̹ÌÁö ½½¶óÀÌ´õ º¸±â

 

DBUtils¿¡¼­ number ŸÀÔÀÇ Ä÷³ÀÌ intÇüÀ¸·Î ¾È³Ñ¾î¿Ã¶§..

 

µ¥ÀÌÅͺ£À̽ºÀÇ Ä÷³ÀÌ NUMBER ŸÀÔÀε¥ VO°´Ã¼ÀÇ intÇü setter¸¦ ÅëÇØ ±× °ªÀÌ ¾È³Ñ¾î ¿À´Â °æ¿ì°¡ ÀÖ½À´Ï´Ù

 

µ¥ÀÌÅͺ£À̽º Å×ÀÌºí ½ºÅ©¸³Æ®

CREATE TABLE user_t (

    user_id VARCHAR2(12) PRIMARY KEY NOT NULL,

    user_point NUMBER(8)

);

 

µ¥ÀÌÅͺ£À̽ºÀÇ °ªÀ» ÀúÀåÇÏ´Â VO °´Ã¼

public class UserVO {

    String user_id;

    int user_point;

 

    public void setUser_id(String user_id) { this.user_id = user_id; }

    public void setUser_point(int user_point) { this.user_point = user_point; }

    public String getUser_id() { return user_id; }

    public int getUser_point() { return user_point; }

}

 

 

JSP

...

ResultSetHandler rsh = new BeanListHandler(UserVO.class);

QueryRunner qr = new QueryRunner();

List list = (List)qr.query(conn, "SELECT user_id, user_point FROM user_t WHERE user_id = ?", new String[]{"unicorn"}, rsh);

...

 

°£´ÜÈ÷ À§¿Í °°ÀÌ ÄÚµùÀ» ÇÏ¸é ´ÙÀ½°ú °°Àº ¿¡·¯ ¸Þ¼¼Áö°¡ ³³´Ï´Ù

java.sql.SQLException Cannot set user_point : argument type mismatch Query

user_point Ä÷³À̶û ¸ÕÁö ¸ð¸£Áö¸¸ ¾Æ±Ô¸ÕÆ®¶û typeÀÌ ¸ÂÁö ¾Ê´Â´Ù´Â ¸» °°±º¿ä

 

DBUtils ¹Þ¾Æ¼­ Â÷±ÙÂ÷±Ù ¼Ò½º¸¦ º¸´Ùº¸´Ï..

org.apache.commons.dbutils.BasicRowProcessor.java

private void callSetter(
    Object target,
    PropertyDescriptor prop,
    Object value)
    throws SQLException {

 

    Method setter = prop.getWriteMethod();
    if (setter == null) {
        return;
    }

    Class[] params = setter.getParameterTypes();
    try {

        // Don't call setter if the value object isn't the right type
        if (this.isCompatibleType(value, params[0]))
            setter.invoke(target, new Object[] { value });  //-- ¨ç

 

    } catch (IllegalArgumentException e) {
        throw new SQLException(
            "Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException(
            "Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (InvocationTargetException e) {
        throw new SQLException(
            "Cannot set " + prop.getName() + ": " + e.getMessage());
    }
}

 

¨ç ÀÇ setter.invoke ¿¡¼­ IllegalArgumentException °¡ throw µÇ°í ÀÖ¾ú½À´Ï´Ù

Áï °ª¿¡ ÇØ´çÇÏ´Â setter ÇÔ¼ö¸¦ ã´Ù°¡ setUser_point(int user_point) °¡ ÀÖÀ½¿¡µµ ºÒ°íÇÏ°í Àû´çÇÑ °ÍÀÌ ¾ø¾î¼­ ExceptionÀ» ´øÁö°í ÀÖ´Â ½ÇÁ¤ÀÔ´Ï´Ù

¿øÀÎÀº value ¶§¹®À̾ú´Âµ¥, ÀÌ´Â

value = rs.getObject(i+1)

¿Í °°ÀÌ resultset¿¡¼­ ¹Þ¾Æ¿Â °ªÀÔ´Ï´Ù

invoke ÇÔ¼ö¿¡ µÎ¹ø° ÆĶó¹ÌÅÍ·Î ObjectÇüÅÂÀÇ °´Ã¼ÇüÅ·Π³Ñ°ÜÁÖ¾î¾ß Çϴµ¥ À̳ÑÀº IntegerÇüÀÌ ¾Æ´Ñ°Í °°¾Ò½À´Ï´Ù

Integer.class.isInstance(value) ·Î °ªÀ» Âï¾îº¸´Ï ¿ª½Ã³ª false°¡ ¸®ÅϵǾú½À´Ï´Ù

 

±×·¡¼­ ´ÙÀ½°ú °°ÀÌ ¾à°£ ¼öÁ¤ÇÏ¿´½À´Ï´Ù

 

private void callSetter(
    Object target,
    PropertyDescriptor prop,
    Object value)
    throws SQLException {

 

    Method setter = prop.getWriteMethod();
    if (setter == null) {
        return;
    }

    Class[] params = setter.getParameterTypes();
    try {

        // Don't call setter if the value object isn't the right type

 

        if (params[0].equals(Integer.TYPE)) {
            value = new Integer(value.toString());  //-- ¨è
       }


        if (this.isCompatibleType(value, params[0]))
            setter.invoke(target, new Object[] { value });  //-- ¨ç

 

    } catch (IllegalArgumentException e) {
        throw new SQLException(
            "Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException(
            "Cannot set " + prop.getName() + ": " + e.getMessage());

    } catch (InvocationTargetException e) {
        throw new SQLException(
            "Cannot set " + prop.getName() + ": " + e.getMessage());
    }
}

 

¨è °ú °°ÀÌ ¸í½ÃÀûÀ¸·Î Integer ŸÀÔÀ϶§ IntegerÇüŸ¦ ¸¸µé¾î ÁÖ¾ú½À´Ï´Ù

MySQL°ú Oracle µÎ°¡Áö Å×½ºÆ®Çغ¸¾Ò´Âµ¥, MySQL¿¡¼­´Â ¹ß»ýÇÏÁö ¾Ê¾ÒÁö¸¸ Oracle¿¡¼­´Â À§¿Í°°Àº ¹®Á¦°¡ ¹ß°ßµÇ¾ú½À´Ï´Ù

¾Æ¸¶µµ M$SQL¿¡¼­µµ µ¿ÀÏÇÑ ¹®Á¦°¡ ¹ß»ýÇÒ°Í °°½À´Ï´Ù

¼Ò½º´Â µ¿ÀÏÇѵ¥ ¾îµð¼± µÇ°í ¾ÈµÇ°í¸¦ º¸´Ï JDBC¿µÇâÀÏ°ÍÀ¸·Î ÃßÃøÀÌ µÇ´Âµ¥, JDBC ¼Ò½º¸¦ º¸¾Æµµ º° Ưº°Çѵ¥´Â ¾ÆÁ÷ ãÁö ¸øÇß½À´Ï´Ù

 

»ç½Ç DBUtils´Â Àß¾²¸é ¹«Ã´ ÆíÇÕ´Ï´Ù

ÇÏÁö¸¸ ¸¹ÀÌ ÁÁ¾ÆÁ³´Ù°í´Â Çϳª reflect¿¡ ´ëÇÑ ºñ¿ë ¾øÀݾƠµé°Ì´Ï´Ù

DBUtils´Â ±× ÀÚü·Î ±¦ÂúÁö¸¸ ¾Æ¸¶ »ç¿ëÇÏ´Ùº¸¸é ¼Ò½º¿¡ ¼ÕÀ» µ¥¾ßµÉ°Ì´Ï´Ù

ÇÑ±Û ÀÎÄÚµù, µðÄÚµùÀ̳ª Äõ¸®µîÀ» DBUtils¿¡ ½É¾î³õÀ¸¸é ÄÚµùÀº ¾Æ¸¶ ´õ ÁÙ¾îµé°Ì´Ï´Ù

 

2010-07-27 16:59:50
211.189.124.***

 

ÁÁÀº»ý°¢ ^^

10Á¡ (2¸í)
µ¡±Û 3°³ | ÅÂ±× 1°³ | °ü·Ã±Ûº¸±â
ű×ÀÔ·Â
½±Ç¥(,)±¸ºÐÀ¸·Î Çѹø¿¡ ¿©·¯ ű׸¦ ÀÔ·ÂÇÒ¼ö ÀÖ½À´Ï´Ù
DBUtils (6)
deuxksy
(0) (0)
Oracle ÀÏ°æ¿ì int ¾Æ´Ï°í BigDecimal ·Î º¯¼ö¼±¾ð Çϸé ÀÌ»ó¾øÀÌ µÊ´Ï´Ù.
124.59.37.*** 2006-07-27 23:01:56
·¹¸óÆÄ¿îµå
(0) (0)

http://kwseo.egloos.com/2557192


Âü°í ¹Ù·¡¿ä ^^


59.27.63.*** 2010-07-27 16:59:50
¿ó½º
(0) (0)

Long ÇüÀ϶§

if(params[0].equals(Long.TYPE))
{
    value = new Long(value.toString()); // -- 3    

}

 

¿ä°Íµµ Ãß°¡ÇØÁÖ¸é Àߵ˴ϴÙ..

221.143.29.*** 2007-08-31 13:41:43
À̸§ ºñ¹Ð¹øÈ£
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ®
ÀÚÄ«¸£Å¸ ÇÁ·ÎÁ§Æ® ÆÁ °Ô½ÃÆÇ ÀÔ´Ï´Ù
! ¹øÈ£ Á¦¸ñ ±Û¾´ÀÌ ÀÏÀÚ Á¶È¸
Hierarchy of the Apache Software Foundation GoodBug 2005-10-14 10,814
Jakarta Project °­Á °Ô½ÃÆÇÀÔ´Ï´Ù 8 GoodBug 2005-04-03 11,701
44 Log4J log4j¿¡¼­ e.printStackTrace() ¸Þ½ÃÁö¸¦ log¿¡ ³²±â´Â ¹æ¹ý 1 kaiser 2008-10-22 17,613
43 DBUtils DBUtils¿¡¼­ Clob »ç¿ëÇϱâ 3 1 GoodBug 2007-08-28 10,633
42 Spring Spring ¼³Á¤ ÆÄÀÏ ·Îµù 1 GoodBug 2007-07-16 11,317
41 POI POIÀÇ HSLF¸¦ ÀÌ¿ëÇÏ¿© PowerPoint ¹®¼­¸¦ ÀоÀÚ 2 GoodBug 2007-05-28 14,910
40 POI POIÀÇ HWPF¸¦ ÀÌ¿ëÇÏ¿© MS WORD¹®¼­¸¦ ÀоÀÚ 2 GoodBug 2007-05-28 16,839
39 Validator Validator ¼Ó¼ºµé 1 GoodBug 2007-05-11 10,404
38 dd Commons-Fileupload 1.2 1 2 GoodBug 2007-04-23 15,345
37 Apache Apache2 + Tomcat5.5 + mod_jk 4 ¹ÙÀÌ·¯½ºô¸国 2007-01-29 11,066
DBUtils DBUtils¿¡¼­ number ŸÀÔÀÇ Ä÷³ÀÌ intÇüÀ¸·Î ¾È³Ñ¾î¿Ã¶§.. 3 1 GoodBug 2006-06-28 10,755
35 ÈìÈì À§ÇèÇÑ static Logger Çʵå... 2 1 ¼­¿¬¾Æºü 2006-03-16 10,113
34 Installing Tomcat with commons-daemon (jsvc) GoodBug 2006-01-08 9,067
33 commons Commons DbUtils ¸î°¡Áö ¿¹Á¦ 3 2 GoodBug 2005-11-17 15,221
32 commons Jakarta Commons Net ¿¡¼­ FTP »ç¿ë½Ã ¸ñ·ÏÀÌ ¾Èº¸ÀÏ °æ¿ì 2 GoodBug 2005-11-15 21,776
31 listFiles() ¿¡¼­ null À» ¹Ýȯ ÃßÀû.. ½Å¸¸µÎ 2008-11-11 11,866
30 commons ¸ñ·ÏÀÌ ¾Èº¸ÀÏ °æ¿ì ÇØ°á±â Iź 1 2 GoodBug 2005-12-23 15,932
29 POI POI·Î ¿¢¼¿ÆÄÀÏ ÀÐÀ»¶§, Invalid header signature ¿¡·¯ 1 GoodBug 2005-11-12 16,540
28 log4j log4j, JSP¿¡¼­ ¿øÇÏ´Â Appender °ñ¶ó¾²±â 1 GoodBug 2005-11-07 13,894
27 commons Commons-Email~ 7 2 GoodBug 2005-10-13 17,860
copyright 2005-2024 by Unicorn