'DEVEL'에 해당되는 글 17건

  1. 2006.10.17 [MySql] auto_increment 값 알아오기 3 by 홍사마
  2. 2006.10.11 web.xml example by 홍사마
  3. 2006.10.11 tomcat 설정 1 by 홍사마
  4. 2006.10.11 스팸와 captcha 1 by 홍사마
  5. 2006.09.28 debian pakage control by 홍사마
  6. 2006.09.27 Eclipse WTP Project by 홍사마
  7. 2006.09.26 Parasoft JTest 1 by 홍사마

네이년에서는 copy&paste가 안되니 직접 쓸 수밖에..ㅡ.ㅡ;;;

=======================================

컬럼타입이 auto_increment이면 insert 시 값을 지정하지 않아도 알아서 자동으로 증가된 값을 사용한다. 그러나 문제는 PK로 사용한 경우 insert 후 그 값을 알 수가 없다는 것이다. 그래서 MySQL에서는 가장 최근에 사용된 auto_increment값을 알수 있게 해주는 함수를 제공한다.

LAST_INSERT_ID()

이 함수는 connection기반으로 가장 최근에 사용된 auto_increment 값을 리턴한다. 사용할 대는 아래와 같이 간단하게.

select LAST_INSERT_ID();

이런 식으로 사용하면 된다.

참고로 auto_increment를 사용할 때 임의로 시작값을 설정하기 위한 것..
alter table "tbl_name" auto_increment = xxx

=================================================

3.6.9. Using AUTO_INCREMENT

The AUTO_INCREMENT attribute can be used to generate a unique identity for new rows:

CREATE TABLE animals (
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (id)
);
INSERT INTO animals (name) VALUES ('dog'),('cat'),('penguin'),
('lax'),('whale'),('ostrich');
SELECT * FROM animals;

Which returns:

+----+---------+
| id | name |
+----+---------+
| 1 | dog |
| 2 | cat |
| 3 | penguin |
| 4 | lax |
| 5 | whale |
| 6 | ostrich |
+----+---------+

You can retrieve the most recent AUTO_INCREMENT value with the LAST_INSERT_ID() SQL function or the mysql_insert_id() C API function. These functions are connection-specific, so their return value is not affected by another connection also doing inserts.

Note: For a multiple-row insert, LAST_INSERT_ID()/mysql_insert_id() actually returns the AUTO_INCREMENT key from the first of the inserted rows. This allows multiple-row inserts to be reproduced correctly on other servers in a replication setup.

For MyISAM and BDB tables you can specify AUTO_INCREMENT on a secondary column in a multiple-column index. In this case, the generated value for the AUTO_INCREMENT column is calculated as MAX(auto_increment_column)+1 WHERE prefix=given-prefix. This is useful when you want to put data into ordered groups.

CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
);
INSERT INTO animals (grp,name) VALUES('mammal','dog'),('mammal','cat'),
('bird','penguin'),('fish','lax'),('mammal','whale'),
('bird','ostrich');SELECT * FROM animals ORDER BY grp,id;

Which returns:

+--------+----+---------+
| grp | id | name |
+--------+----+---------+
| fish | 1 | lax |
| mammal | 1 | dog |
| mammal | 2 | cat |
| mammal | 3 | whale |
| bird | 1 | penguin |
| bird | 2 | ostrich |
+--------+----+---------+

Note that in this case (when the AUTO_INCREMENT column is part of a multiple-column index), AUTO_INCREMENT values are reused if you delete the row with the biggest AUTO_INCREMENT value in any group. This happens even for MyISAM tables, for which AUTO_INCREMENT values normally are not reused.)

If the AUTO_INCREMENT column is part of multiple indexes, MySQL will generate sequence values using the index that begins with the AUTO_INCREMENT column, if there is one. For example, if the animals table contained indexes PRIMARY KEY (grp, id) and INDEX (id), MySQL would ignore the PRIMARY KEY for generating sequence values. As a result, the table would contain a single sequence, not a sequence per grp value.

==================================================================

LAST_INSERT_ID()
LAST_INSERT_ID(expr)
Returns the last automatically generated value that was inserted into an AUTO_INCREMENT column.
mysql> SELECT LAST_INSERT_ID();        -> 195
커넥트 단워로 값이 유지됨으로 다른 사용자에 의해서 값이 바뀌지 않습니다.
The last ID that was generated is maintained in the server on a per-connection basis. This means the value the function returns to a given client is the most recent AUTO_INCREMENT value generated by that client. The value cannot be affected by other clients, even if they generate AUTO_INCREMENT values of their own. This behavior ensures that you can retrieve your own ID without concern for the activity of other clients, and without the need for locks or transactions. The value of LAST_INSERT_ID() is not changed if you update the AUTO_INCREMENT column of a row with a non-magic value (that is, a value that is not NULL and not 0). If you insert many rows at the same time with an insert statement, LAST_INSERT_ID() returns the value for the first inserted row. The reason for this is to make it possible to easily reproduce the same INSERT statement against some other server. If you use INSERT IGNORE and the record is ignored, the AUTO_INCREMENT counter still is incremented and LAST_INSERT_ID() returns the new value. If expr is given as an argument to LAST_INSERT_ID(), the value of the argument is returned by the function and is remembered as the next value to be returned by LAST_INSERT_ID(). This can be used to simulate sequences:
  • Create a table to hold the sequence counter and initialize it:
    mysql> CREATE TABLE sequence (id INT NOT NULL);mysql> INSERT INTO sequence VALUES (0);
  • Use the table to generate sequence numbers like this:
    mysql> UPDATE sequence SET id=LAST_INSERT_ID(id+1);mysql> SELECT LAST_INSERT_ID();
    The UPDATE statement increments the sequence counter and causes the next call to LAST_INSERT_ID() to return the updated value. The SELECT statement retrieves that value. The mysql_insert_id() C API function can also be used to get the value. See section 21.2.3.33 mysql_insert_id().
You can generate sequences without calling LAST_INSERT_ID(), but the utility of using the function this way is that the ID value is maintained in the server as the last automatically generated value. It is multi-user safe because multiple clients can issue the UPDATE statement and get their own sequence value with the SELECT statement (or mysql_insert_id()), without affecting or being affected by other clients that generate their own sequence values. Note that mysql_insert_id() is only updated after INSERT and UPDATE statements, so you cannot use the C API function to retrieve the value for LAST_INSERT_ID(expr) after executing other SQL statements like SELECT or SET.
Posted by 홍사마

web.xml example

DEVEL : 2006. 10. 11. 21:15

이것도 역시 퍼온거.. 내일 읽어봐야지..

=========================================

출처 : 용이 님의 블로그

http://blog.naver.com/igilyong/140014772951

[Tomcat] web.xml에 대한 예제..

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>


<!-- 웹 어플리케이션의 일반적 설명 -->

<display-name>My Web Application</display-name>
<description>
이것은 와일드하고 훌륭한 작업을 수행하는 servlet과 JSP
기반한 애플리케이션의 X.X 버전입니다. 이 문서는 개발자
Dave 가 작성했고, 더 자세한 정보를 원하시면
dave@mycompany.com 으로 연락할 수 있습니다.
</description>


<!-- Context 초기 파라메터: 어플리케이션에서 사용되는 공유
된 문자열 상수들을 선언합니다. 이것은 애플리케이션을
설치하는 시스템 관리자가 변경할 수 있습니다. 이들 파
라메터에 실질적으로 할당된 값들은 servlet 과 JSP page
에서 다음과 같이 불러올 수 있습니다:

String value =
getServletContext().getInitParameter("name");

여기서 "name" 은 <param-name> 이들 초기 파라메터 중에
하나의 엘리먼트와 같습니다.

컨텍스트 초기 파라메터의 갯수는 제한이 없고, 아무것도
없어도 됩니다.
-->

<context-param>
<param-name>webmaster</param-name>
<param-value>myaddress@mycompany.com</param-value>
<description>
The EMAIL address of the administrator to whom questions
and comments about this application should be addressed.
</description>
</context-param>


<!-- 초기 파라메터를 포함해, 웹 애플리케이션을 구성하는
servlet 에 대한 정의. Tomcat 에서, 브라우저에서 servlet
요청시 아래와 같이 함으로 web.xml 파일에 등록안된 것도
부를 수 있습니다:

http://localhost:8080/{context-path}/servlet/{classname}

그러나 이런 사용법은 유동성을 보장하지 못합니다. 또한
servlet이 이미지나 다른 자원에 접근하기 위해서는 상대 경로
를 지정해야 되는 등 servlet이 매우 복잡하게 됩니다. 그래서
모든 servlet 을 정의해 주는 것을 (그리고 servlet-매핑 요소
로 정의하는 것) 권장합니다.

Servlet 초기 파라메터는 servlet 과 JSP page 에서 다음과 같
이 불러올 수 있습니다:

String value =
getServletConfig().getInitParameter("name");

여기서 "name" 은 <param-name> 이들 초기 파라메터 중에
하나의 엘리먼트와 같습니다.

servlet 갯수는 제한이 없고, 아무것도 없어도 됩니다.
-->

<servlet>
<servlet-name>controller</servlet-name>
<description>
이 어플리케이션에 사용된 MVC 구조에서 이 servlet은 "controller"
역할을 합니다. 보통 <servlet-mapping> 엘리먼트와 함께 ".do" 파일
확장자로 매핑됩니다. 그리고 이 애플리케이션에서 사용되는 모든
form은 요청하는 주소가 "saveCustomer.do" 처럼 지정됩니다. 이
servlet에 매핑된 servlet입니다.

이 servlet에 대한 초기 파라메터 명은 (파일 확장자가 제거된 후에)
이 servlet 이 받는 "servlet path" 입니다. 상응하는 값은 이 요청을
처리하는 데 사용할 action class 의 이름입니다.
</description>
<servlet-class>com.mycompany.mypackage.ControllerServlet</servlet-class>
<init-param>
<param-name>listOrders</param-name>
<param-value>com.mycompany.myactions.ListOrdersAction</param-value>
</init-param>
<init-param>
<param-name>saveCustomer</param-name>
<param-value>com.mycompany.myactions.SaveCustomerAction</param-value>
</init-param>
<!-- 시동할 때 이 servlet을 서버에 로딩한다 -->
<load-on-startup>5</load-on-startup>
</servlet>

<servlet>
<servlet-name>graph</servlet-name>
<description>
이 servlet 은 동적으로 생성된 그래프 GIF 이미지를 생성합니다.
이 요청에 포함된 입력된 파라메터값을 갖고 생성합니다. 보통
"/graph" 라는 구별된 URI 요청에 매핑되어 있습니다.
</description>
</servlet>


<!-- 특정한 요청 URI (context-상대적인)를 특정한 servlet으로 해석
하는 servlet 컨테이너에 의해 사용되는 매핑을 선언하기.
아래 예제는 위에 있는 servlet 설명과 관계있습니다. 그러므로,
요청 URI 는 다음과 같습니다:

http://localhost:8080/{contextpath}/graph

주소는 "graph" servlet 에 매핑됩니다. 한편:

http://localhost:8080/{contextpath}/saveCustomer.do

은 "controller" servlet 에 매핑됩니다.

servlet 매핑의 갯수는 제한이 없고, 아무것도 없어도 됩니다.
원한다면 하나의 servlet 에 한 개 이상의 매핑을 해주어도 됩니다.
-->

<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>graph</servlet-name>
<url-pattern>/graph</url-pattern>
</servlet-mapping>


<!-- 어플리케이션의 기본 세션 타임아웃 시간을 분단위로 설정합
니다. servlet 이나 JSP page 에서, 동적으로 특정한 session
에 대해 시간을 조정할 수 있습니다.
HttpSession.getMaxInactiveInterval() 을 사용하면 됩니다.
-->

<session-config>
<session-timeout>30</session-timeout> <!-- 30 minutes -->
</session-config>


</web-app>

<error-page>
<error-code>
500
</error-code>
<location>
/errorPage.jsp
</location>
</error-page>
<error-page>
<exception-type>
javax.servlet.ServletException
</exception-type>
<location>
/servlet/ErrorDisplay
</location>
</error-page>

Posted by 홍사마

tomcat 설정

DEVEL : 2006. 10. 11. 21:00
역시 한글 문서는 네이년이 잘 찾는군...역시 자기네 블로그 유저들로 인한 것들..네이년~

일단 URL만...평가는 나중에~

http://blog.naver.com/dlawnd5/120029099603


자바 환경 설치 (Java, JDK, Eclipse, mySQL, tomcat, Web) | 중선이 블로그2006/09/19 10:28
http://blog.naver.com/dlawnd5/120029099603

1. 자바 설치


  1) JDK 다운 받기

  http://java.sun.com/javase/downloads/index.jsp


  2) 환경변수 등록

  내컴퓨터->등록정보->고급->환경변수->사용자변수/시스템변수  (추가 또는 편집)


  JAVA_HOME

             C:\Program Files\Java\jdk1.5.0_08


  PATH   (시스템/사용자)

             C:\Program Files\Java\jdk1.5.0_08\bin ;

             C:\Program Files\Java\jdk1.5.0_08\lib\tools.jar;


  CLASSPATH

             .;

             C:\Program Files\Java\jdk1.5.0_08\jre\lib\rt.jar;


  3) 확인

  시작->실행->cmd

             java

             javac




----------------------------------------------------------------------------------


2. Eclipse 설치

  1) Eclipse 다운 받기

   http://www.eclipse.org/downloads/


  2) WTP가 세팅된 이클립스 다운받기 (웹 서버를 사용하려면 WTP가 필요)

   http://www.eclipse.org/webtools/


   downloads -> Latest Downloads -> 버전 선택 -> WebTools Platform; All-in-one

   에서 다운을 받는다.


  3) 압축을 풀고 eclipse.exe 실행하면 됨.




----------------------------------------------------------------------------------


3. mySQL 설치


  1) 다운 받기

   http://dev.mysql.com/downloads/


   MySQL community Edition : Current Release

   MySQL Tools : mySQL GUI Tools

   Drivers and Connectors  : mySQL connector/J (JDBC)

  

   2) 설치

   mySQL을 설치 => GUI tools 설치

   mySQL connector 압축 풀기

  

   3) 이클립스 연동

   프로젝트 Properties -> Java Build Path -> Libraries -> AddExternal JARs...

   mysql-connector-java 의 jar파일 추가.


   4) 연결 및 사용

    DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());

    Connection conn = DriverManager.getConnection(url, id, psw);

    Statement stmt = conn.createStatement();

    (url - jdbc:mysql://localhost:3306/xxxx)


    // insert,update

    stmt.executeUpdate(query);


    // select

    ResultSet rs = stmt.executeQuery(query);


    conn.close();

    stmt.close();




----------------------------------------------------------------------------------


3. tomcat 설치


  1) 다운받기

  톰켓 -  http://tomcat.apache.org/

  플러그인 - http://www.sysdeo.com/eclipse/tomcatplugin


  2) 설치   

  톰켓 - 압축 풀기.

         - bin/startup.bat 실행 후

         - http://localhost:8080/   <== 되는지 확인

        - shutdown.bat 으로 종료.


  플러그인

         - eclipse\plugins에 복사  


  3) 이클립스 연동

         고양이 아이콘이 추가 되었는지 확인

         메뉴 Window -> Show View -> Other -> Server -> Servers

         아래쪽에 Servers 탭 확인

         아래쪽에서 마우스 오른쪽 버튼 -> New -> Server

         Server 선택(Next) -> tomcat 위치 지정

         아래쪽 Server 추가된 것 확인.




----------------------------------------------------------------------------------


4. Web Project


  1) 프로젝트 생성

      Java Project 선택.

     

  2) 폴더 구성  

      src

      web - WEB-INF - classes

                             - lib


      src : 소스 폴더

      classes : out put


      apache-tomcat-5.5.17\webapps\ROOT\WEB-INF\web.xml을 복사하여

      WEB-INF 에 web.xml추가


      web 에 index.html 및 jsp 파일 추가.

      index.html에 아무말이나 작성.


      web.xml 수정.

     <servlet-mapping><url-pattern>을 참조하여 <servlet-mapping><servlet-name>과

     <servlet><servlet-name>을 매핑하여, <servlet><servlet-class>를 생성한다.


  3) 프로젝트와 톰켓 연결

      아래쪽 이전에 생성시킨 Server 더블 클릭

      modules 탭에서 Add External Web Module을 눌러 Web Module 추가.

      위에 생성한 프로젝트의 web 폴더를 Decoment base로 설정.

      Path는 /sss  <==암거나


   4) 서버구동

      Server -> 마우스 오른쪽 버튼 -> Start

      http://localhost:8080/sss

      확인


Posted by 홍사마

스팸와 captcha

DEVEL : 2006. 10. 11. 20:41

captcha에 대해서 검색을 하던 중에 아래의 글을 발견..


==========================================


최근 웹 사이트에서 스펨이나 로봇에 의한 가입을 방지하고자 CAPTCHA를 많이 도입하고 있다. CAPTCHA 라는 것은 사람들은 쉽게 읽을 수 있는 글자지만 컴퓨터는 읽을 수 없도록 고안된 글자이다. 하지만 최근 W3C에서 나온 Inaccessibility of CAPTCHA라는 Note에 의하면 이는 시각 장애를 가지고 있는 사람들에게 끔찍한 불편을 주면서도 실제로 스펨이나 로봇을 막아내는 역할은 쉽게 깨질 수 있다고 한다. 실제로 Breaking a Visual CAPTCHA라는 글에 의하면 현재 많이 쓰이는 형태의 CAPTCHA의 92%를 읽어낼 수 있다고 한다. 따라서 시각 장애인에게 불편만 주고 실제 보호는 이루어지지 못하는 CAPTCHA 대신 퍼즐, 음성에 의한 검사, 임시 계정 등을 사용하라고 한다. 하지만 이 또한 장기적으로 효과적일지는 미지수다.

http://www.captcha.net/

http://www.w3.org/TR/2005/NOTE-turingtest-20051123/
http://www.cs.sfu.ca/~mori/research/gimpy/

Posted by 홍사마

debian pakage control

DEVEL : 2006. 9. 28. 21:18

나중에 찾아보기 귀찮아서 하나 남김..

mv skype_1.2.0.17-1_i386.deb skype_1.2.0.17-1_i386.deb.orig

mkdir skype.tmp

dpkg-deb --extract skype_1.2.0.17-1_i386.deb.orig skype.tmp

dpkg-deb --control skype_1.2.0.17-1_i386.deb.orig skype.tmp/DEBIAN

# Now use your favorite editor to edit the Depends line as above:

vi skype.tmp/DEBIAN/control

dpkg --build skype.tmp

mv skype.tmp.deb skype_1.2.0.17-1_i386.deb

Posted by 홍사마

Eclipse WTP Project

DEVEL : 2006. 9. 27. 16:10

eclipse를 다시 건들게 되면서 보게된 것..
기능이 뭔지는 아직 모르겠지만


http://www.eclipse.org/webtools/

The Eclipse Web Tools Platform (WTP) project extends the Eclipse platform with tools for developing J2EE Web applications. The WTP project includes the following tools: source editors for HTML, Javascript, CSS, JSP, SQL, XML, DTD, XSD, and WSDL; graphical editors for XSD and WSDL; J2EE project natures, builders, and models and a J2EE navigator; a Web service wizard and explorer, and WS-I Test Tools; and database access and query tools and models.

기존에 웹개발을 할 때 필요한 plugin을 모아놓은 거라고 생각하면 될 것 같은데...아직 안 써봐서 모르겠삼~
이번에 한번 써봐야지

Posted by 홍사마

Parasoft JTest

DEVEL : 2006. 9. 26. 16:33

예전에 웹페이지를 만들때 junit test를 만들곤 했다. 그런데 이 작업은 나중을 위해서는 좋은 건 알았지만 처음해보다보니 매우 귀찮은 작업처럼 느껴졌다. 그래서 기존에 있던 test에 가끔 추가를 하곤 했다.

그.러.나! 이제 이것을 알아서 만들어주는 툴이 생겼으니 이것이 바로 jtest라는 툴이다(이툴을 소개해준 SJH군께 감사). 지금 이것저것 받아서 테스트를 해보니 language의 specific feature를 이용하여 몇가지는 잡아주는 듯하나 logical defect은 못 잡아주는 듯하다(내가 너무 많은 걸 바라나? ㅡ.ㅡ;;).

앞으로 이것을 사용을 할려고 하는데 종종 사용법을 올릴 듯.. 아직 그냥 프로젝트에 basic configuration을 가지고 돌려본 것이 다라서 coverage가 70%초반인듯...좀 더 사용해보고 계속 사용법을 남기도록 해야겠다.



http://www.parasoft.com/jsp/products/support/presentation/flash/jtest/demo/7.0/JTD.html
Posted by 홍사마