본문 바로가기

IT Data/#Java

SQL Bean.java 의 기본 메소드 형태



public String getEtcMemo(String privateKey){
String memo = ""; 
try{ DBmgr	= new DBConnection(this); 
con	= DBmgr.getConnection();

 sqlStr = new StringBuffer(); sqlStr.append("SELECT * FROM LOG \n"); 
sqlStr.append("WHERE PRIVATE_KEY = ? \n");
 pstmt = con.prepareStatement(sqlStr.toString()); 
pstmt.setString(1, privateKey);
 rs = pstmt.executeQuery(); 
rtResult = new ReturnResult(rs);
 if(rtResult.getRowCount() == 1) memo = rtResult.getValue(0, "memo").toString();
 }catch(SQLException e){ e.printStackTrace();
 }catch(Exception e){ e.printStackTrace();
 }finally{ if ( rs != null )	try{rs.close();
	}catch(Exception e1){} if ( pstmt != null )	try{pstmt.close();
 }catch(Exception e2){} if ( con != null )	try{DBmgr.release();
	}catch(Exception e3){} } return memo;
 }
형태를 취한다. 스프링이나 아이바티스를 활용하면 더욱 간단하게 사용 할 수 있다.