본문 바로가기
[ Web ]/JAVA_JSP_TOMCAT_Eclipse

한글 초성 검색 방법

by 관이119 2012. 9. 13.
출처 찌니 | 비밀
원문 http://blog.naver.com/jincyber09/80100554626

 

1. 초성은 19자로
ㄱ, ㄲ, ㄴ, ㄷ, ㄸ, ㄹ, ㅁ, ㅂ, ㅃ, ㅅ,
ㅆ, ㅇ, ㅈ, ㅉ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ


2. 중성은 21자로
ㅏ, ㅐ, ㅑ, ㅒ, ㅓ, ㅔ, ㅕ, ㅖ, ㅗ, ㅘ,
ㅙ, ㅚ, ㅛ, ㅜ, ㅝ, ㅞ, ㅟ, ㅠ, ㅡ, ㅢ,



3. 종성은 27자로
ㄱ, ㄲ, ㄳ, ㄴ, ㄵ, ㄶ, ㄷ, ㄹ, ㄺ,
ㄻ, ㄼ, ㄽ, ㄾ, ㄿ, ㅀ, ㅁ, ㅂ, ㅄ, ㅅ,
ㅆ, ㅇ, ㅈ, ㅊ, ㅋ, ㅌ, ㅍ, ㅎ


<규칙1>
1.중성이 바뀌는 경우 코드값 차이 : 28
2.초성이 바뀌는 경우 코드값 차이 : 588(21*28)
3.한글에 대한 첫 코드값('가'의 코드값): 44032

<응용>
가 - 44032
까 - 44620
나 - 45208
다 - 45796
따 - 46384
라 - 46972
마 - 47560
바 - 48148
빠 - 48736
사 - 49324
싸 - 49912
아 - 50500
자 - 51088
짜 - 51676
차 - 52264
카 - 52852
타 - 53440
파 - 54028
하 - 54616

초성: 글자의 코드에서 44032를 빼고, 21*28로 나눈 몫 0 ~ 18
중성: 글자의 코드에서 44032를 빼고, 21*28로 나눈 나머지를 다시 28로 나눈 몫 0 ~ 20
종성: 글자의 코드에서 44032를 빼고, 21*28로 나눈 나머지를 다시 28로 나눈 나머지 0 ~ 27

package bean;

import java.sql.*;
import java.util.*;

public class Select_Entry{


private DBConnectionMgr pool=null;
public Select_Entry(){
try{
pool = DBConnectionMgr.getInstance();
}catch(Exception e){
System.out.println("Error : JDBC드라이버 로딩실패");
}

}


//한글에서 초성 뽑아내는 함수
public String Direct(String name){
char b =name.charAt(0);
String chosung = null;
int first = (b - 44032 ) / ( 21 * 28 );
switch(first){
case 0:
case 1:
chosung="ㄱ";
break;
case 2:
chosung="ㄴ";
break;
case 3:
case 4:
chosung="ㄷ";
break;
case 5:
chosung="ㄹ";
break;
case 6:
chosung="ㅁ";
break;
case 7:
case 8:
chosung="ㅂ";
break;
case 9:
case 10:
chosung="ㅅ";
break;
case 11:
chosung="ㅇ";
break;
case 12:
case 13:
chosung="ㅈ";
break;
case 14:
chosung="ㅊ";
break;
case 15:
chosung="ㅋ";
break;
case 16:
chosung="ㅌ";
break;
case 17:
chosung="ㅍ";
break;
case 18:
chosung="ㅎ";
break;

}

return chosung;
}


//회사이름 검색하는 함수(직접검색과 초성검색시 호출)
public Vector Search_name(int type,String name){

Vector pass = new Vector();
Connection con=null;
Statement pstmt=null;
PreparedStatement pstmt1=null;
ResultSet rs=null;
String sql="";
String b=Direct(name);

try{
con=pool.getConnection();
if(type==3){//초성검색의 경우
sql="select * from company where search='"+b+"'order by binary(company_name)";
}
else if(type==2){//직접검색의 경우
sql="select * from (select * from company where search='"+b+"'order by company_name )aa where aa.company_name like '"+name+"%'";
}
pstmt=con.createStatement();
rs=pstmt.executeQuery(sql);
while(rs.next()) {
Company list = new Company();
list.setJ_address(rs.getString("j_address"));
list.setCompany_name(rs.getString("company_name"));
list.setJ_tele(rs.getString("j_tele"));
pass.addElement(list);
}//while
}catch(Exception e){
e.printStackTrace();
}finally{
pool.freeConnection(con,pstmt,rs);

}
return pass;
}


// 회사 등록함수(직접검색과 초성검색시 호출)
public Vector Insert_Company(Company com){

Vector pass = new Vector();
Connection con=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
String sql="";
String chosung=Direct(com.getCompany_name());

try{

con=pool.getConnection();

sql="insert into company values(auto_no.nextval,?,?,?,?,?,?)";
pstmt=con.prepareStatement(sql);
pstmt.setString(1, com.getCompany_name());
pstmt.setString(2, com.getCompany_number());
pstmt.setString(3, com.getJ_address());
pstmt.setString(4, com.getJ_tele());
pstmt.setString(5, com.getJ_fax());
pstmt.setString(6, chosung);
rs=pstmt.executeQuery();
while(rs.next()) {
Company list = new Company();
list.setJ_address(rs.getString("j_address"));
list.setCompany_name(rs.getString("company_name"));
list.setJ_tele(rs.getString("j_tele"));
pass.addElement(list);
}//while
}catch(Exception e){
e.printStackTrace();
}finally{
pool.freeConnection(con,pstmt,rs);

}
return pass;
}


public String[] Login_info(String id){
String[] info=new String[2];
Connection conn=null;
PreparedStatement pstmt =null;
ResultSet rs = null;
String sql=null;
try {
conn=pool.getConnection();
sql="select * from user_info where id=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1,id);
rs=pstmt.executeQuery();
while(rs.next()){
info[0]=rs.getString("name");
info[1]=Integer.toString(rs.getInt("gaip_mode"));
}


}catch(Exception ex){
System.out.println("Exception"+ex);
}finally{
pool.freeConnection(conn,pstmt,rs);
}
return info;
}

}

댓글