이번엔 BoardDAO 소스를 살펴보도록 하겠습니다.
/*
* Created on 2004. 11. 26.
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.board.model;
import java.sql.*;
import com.bitmechanic.sql.*;
import com.board.util.*;
import java.util.*;
/**
* @author suny
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class BoardDAO {
private static String INSERT_QUERY = "INSERT INTO board ( sno , top , vno , id , title , content ) VALUES ( ? , ? , ? , ? , ? , ? )";
private static String MAX_SNO_QUERY = "SELECT /*+ INDEX_DESC(board SYS_C003599) */ nvl(max(sno),0)+1 FROM board WHERE sno > 0";
private static String GET_VNO_QUERY = "SELECT seq_board.nextval FROM dual";
private static String COUNT_QUERY = "SELECT count(*) FROM board WHERE sno > 0";
private static String LIST_QUERY = "SELECT sno , vno , top , title , id FROM board WHERE vno >= ( SELECT vno FROM ( SELECT rownum rnum , vno FROM board WHERE vno > ' ' AND rownum <= ? ) WHERE rnum = ? ) AND rownum <= 10";
private static String VIEW_QUERY = "SELECT sno , vno , top , title , id , content FROM board WHERE sno = ?";
private static String NEXT_PREV_QUERY = "SELECT sno , vno , top , 'NEXT' navi FROM board WHERE vno = ( SELECT /*+ index(board idx_board) */ vno FROM board WHERE vno > ? AND rownum <= 1 ) UNION ALL SELECT sno , vno , top , 'PREV' navi FROM board WHERE vno = ( SELECT /*+ index_desc(board idx_board) */ vno FROM board WHERE vno < ? AND rownum <= 1 )";
private static String DELETE_QUERY = "DELETE FROM board WHERE sno = ?";
private static String UPDATE_QUERY = "UPDATE board SET title = ? , id = ? , content = ? WHERE sno = ?";
public boolean createBoard ( Board board )
{
Connection con = null;
PreparedStatement pstmt = null;
PreparedStatement pstmt2 = null;
ResultSet rs = null;
int iMaxSno = 0;
StringBuffer szTemp = new StringBuffer();
BoardUtil util = new BoardUtil();
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
con.setAutoCommit(false);
pstmt = con.prepareStatement(MAX_SNO_QUERY);
rs = pstmt.executeQuery();
if ( rs.next() )
iMaxSno = rs.getInt(1);
rs.close();
pstmt.close();
pstmt2 = con.prepareStatement(INSERT_QUERY);
pstmt2.setInt(1,iMaxSno);
int iTop = board.getTop();
if ( iTop != 0 )
pstmt2.setInt(2,iTop);
else
pstmt2.setInt(2,iMaxSno);
String szVno = board.getVno();
if ( szVno != "" )
{
szTemp.append(board.getVno());
szTemp.append(".");
szTemp.append(Integer.toString(iMaxSno));
szVno = szTemp.toString();
pstmt2.setString(3,szVno);
pstmt2.setString(4,board.getId());
pstmt2.setString(5,board.getTitle());
pstmt2.setString(6,board.getContent());
}
else
{
pstmt = con.prepareStatement(GET_VNO_QUERY);
rs = pstmt.executeQuery();
if ( rs.next() )
pstmt2.setString(3,Integer.toString((rs.getInt(1))));
pstmt2.setString(4,util.kscToasc(board.getId()));
pstmt2.setString(5,util.kscToasc(board.getTitle()));
pstmt2.setString(6,util.kscToasc(board.getContent()));
}
pstmt2.executeUpdate();
con.commit();
rs.close();
pstmt.close();
pstmt2.close();
con.close();
return true;
}
catch ( Exception e1 )
{
try
{
con.rollback();
e1.printStackTrace();
return false;
}
catch ( Exception ignore )
{
}
}
finally
{
try
{
if ( rs != null )
rs.close();
if ( pstmt != null )
pstmt.close();
if ( pstmt2 != null )
pstmt2.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
return false;
}
public boolean deleteBoard(int sno)
{
Connection con = null;
PreparedStatement pstmt = null;
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
con.setAutoCommit(false);
pstmt = con.prepareStatement(DELETE_QUERY);
pstmt.setInt(1,sno);
if ( pstmt.executeUpdate() > 0 )
{
con.commit();
return true;
}
else
return false;
}
catch ( Exception e1 )
{
try
{
con.rollback();
e1.printStackTrace();
return false;
}
catch ( Exception ignore )
{
}
}
finally
{
try
{
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
return false;
}
public boolean updateBoard(Board board)
{
Connection con = null;
PreparedStatement pstmt = null;
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
con.setAutoCommit(false);
pstmt = con.prepareStatement(UPDATE_QUERY);
pstmt.setString(1,board.getTitle());
pstmt.setString(2,board.getId());
pstmt.setString(3,board.getContent());
pstmt.setInt(4,board.getSno());
if ( pstmt.executeUpdate() > 0 )
{
con.commit();
return true;
}
else
return false;
}
catch ( Exception e1 )
{
try
{
con.rollback();
e1.printStackTrace();
return false;
}
catch ( Exception ignore )
{
}
}
finally
{
try
{
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
return false;
}
public List getBoardList(int iPageNum)
{
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int iRnum , iGetNumber;
List boardList = new ArrayList();
try
{
iRnum = iPageNum * 10;
iGetNumber = iRnum - 9;
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
pstmt = con.prepareStatement(LIST_QUERY);
pstmt.setInt(1,iRnum);
pstmt.setInt(2,iGetNumber);
rs = pstmt.executeQuery();
while ( rs.next() )
{
Board board = new Board();
board.setSno(rs.getInt(1));
board.setVno(rs.getString(2));
board.setTop(rs.getInt(3));
board.setTitle(rs.getString(4));
board.setId(rs.getString(5));
boardList.add(board);
}
return boardList;
}
catch ( Exception e1 )
{
e1.printStackTrace();
return boardList;
}
finally
{
try
{
if ( rs != null )
rs.close();
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
}
public Board getBoardContent(int sno)
{
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
// "SELECT sno , vno , top , title , id , content FROM board WHERE sno = ?";
pstmt = con.prepareStatement(VIEW_QUERY);
pstmt.setInt(1,sno);
rs = pstmt.executeQuery();
if ( rs.next() )
{
Board board = new Board();
board.setSno(rs.getInt(1));
board.setVno(rs.getString(2));
board.setTop(rs.getInt(3));
board.setTitle(rs.getString(4));
board.setId(rs.getString(5));
board.setContent(rs.getString(6));
return board;
}
else
return null;
}
catch ( Exception e1 )
{
e1.printStackTrace();
return null;
}
finally
{
try
{
if ( rs != null )
rs.close();
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
}
/*
* Created on 2004. 11. 26.
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.board.model;
import java.sql.*;
import com.bitmechanic.sql.*;
import com.board.util.*;
import java.util.*;
/**
* @author suny
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class BoardDAO {
private static String INSERT_QUERY = "INSERT INTO board ( sno , top , vno , id , title , content ) VALUES ( ? , ? , ? , ? , ? , ? )";
private static String MAX_SNO_QUERY = "SELECT /*+ INDEX_DESC(board SYS_C003599) */ nvl(max(sno),0)+1 FROM board WHERE sno > 0";
private static String GET_VNO_QUERY = "SELECT seq_board.nextval FROM dual";
private static String COUNT_QUERY = "SELECT count(*) FROM board WHERE sno > 0";
private static String LIST_QUERY = "SELECT sno , vno , top , title , id FROM board WHERE vno >= ( SELECT vno FROM ( SELECT rownum rnum , vno FROM board WHERE vno > ' ' AND rownum <= ? ) WHERE rnum = ? ) AND rownum <= 10";
private static String VIEW_QUERY = "SELECT sno , vno , top , title , id , content FROM board WHERE sno = ?";
private static String NEXT_PREV_QUERY = "SELECT sno , vno , top , 'NEXT' navi FROM board WHERE vno = ( SELECT /*+ index(board idx_board) */ vno FROM board WHERE vno > ? AND rownum <= 1 ) UNION ALL SELECT sno , vno , top , 'PREV' navi FROM board WHERE vno = ( SELECT /*+ index_desc(board idx_board) */ vno FROM board WHERE vno < ? AND rownum <= 1 )";
private static String DELETE_QUERY = "DELETE FROM board WHERE sno = ?";
private static String UPDATE_QUERY = "UPDATE board SET title = ? , id = ? , content = ? WHERE sno = ?";
public boolean createBoard ( Board board )
{
Connection con = null;
PreparedStatement pstmt = null;
PreparedStatement pstmt2 = null;
ResultSet rs = null;
int iMaxSno = 0;
StringBuffer szTemp = new StringBuffer();
BoardUtil util = new BoardUtil();
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
con.setAutoCommit(false);
pstmt = con.prepareStatement(MAX_SNO_QUERY);
rs = pstmt.executeQuery();
if ( rs.next() )
iMaxSno = rs.getInt(1);
rs.close();
pstmt.close();
pstmt2 = con.prepareStatement(INSERT_QUERY);
pstmt2.setInt(1,iMaxSno);
int iTop = board.getTop();
if ( iTop != 0 )
pstmt2.setInt(2,iTop);
else
pstmt2.setInt(2,iMaxSno);
String szVno = board.getVno();
if ( szVno != "" )
{
szTemp.append(board.getVno());
szTemp.append(".");
szTemp.append(Integer.toString(iMaxSno));
szVno = szTemp.toString();
pstmt2.setString(3,szVno);
pstmt2.setString(4,board.getId());
pstmt2.setString(5,board.getTitle());
pstmt2.setString(6,board.getContent());
}
else
{
pstmt = con.prepareStatement(GET_VNO_QUERY);
rs = pstmt.executeQuery();
if ( rs.next() )
pstmt2.setString(3,Integer.toString((rs.getInt(1))));
pstmt2.setString(4,util.kscToasc(board.getId()));
pstmt2.setString(5,util.kscToasc(board.getTitle()));
pstmt2.setString(6,util.kscToasc(board.getContent()));
}
pstmt2.executeUpdate();
con.commit();
rs.close();
pstmt.close();
pstmt2.close();
con.close();
return true;
}
catch ( Exception e1 )
{
try
{
con.rollback();
e1.printStackTrace();
return false;
}
catch ( Exception ignore )
{
}
}
finally
{
try
{
if ( rs != null )
rs.close();
if ( pstmt != null )
pstmt.close();
if ( pstmt2 != null )
pstmt2.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
return false;
}
public boolean deleteBoard(int sno)
{
Connection con = null;
PreparedStatement pstmt = null;
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
con.setAutoCommit(false);
pstmt = con.prepareStatement(DELETE_QUERY);
pstmt.setInt(1,sno);
if ( pstmt.executeUpdate() > 0 )
{
con.commit();
return true;
}
else
return false;
}
catch ( Exception e1 )
{
try
{
con.rollback();
e1.printStackTrace();
return false;
}
catch ( Exception ignore )
{
}
}
finally
{
try
{
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
return false;
}
public boolean updateBoard(Board board)
{
Connection con = null;
PreparedStatement pstmt = null;
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
con.setAutoCommit(false);
pstmt = con.prepareStatement(UPDATE_QUERY);
pstmt.setString(1,board.getTitle());
pstmt.setString(2,board.getId());
pstmt.setString(3,board.getContent());
pstmt.setInt(4,board.getSno());
if ( pstmt.executeUpdate() > 0 )
{
con.commit();
return true;
}
else
return false;
}
catch ( Exception e1 )
{
try
{
con.rollback();
e1.printStackTrace();
return false;
}
catch ( Exception ignore )
{
}
}
finally
{
try
{
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
return false;
}
public List getBoardList(int iPageNum)
{
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
int iRnum , iGetNumber;
List boardList = new ArrayList();
try
{
iRnum = iPageNum * 10;
iGetNumber = iRnum - 9;
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
pstmt = con.prepareStatement(LIST_QUERY);
pstmt.setInt(1,iRnum);
pstmt.setInt(2,iGetNumber);
rs = pstmt.executeQuery();
while ( rs.next() )
{
Board board = new Board();
board.setSno(rs.getInt(1));
board.setVno(rs.getString(2));
board.setTop(rs.getInt(3));
board.setTitle(rs.getString(4));
board.setId(rs.getString(5));
boardList.add(board);
}
return boardList;
}
catch ( Exception e1 )
{
e1.printStackTrace();
return boardList;
}
finally
{
try
{
if ( rs != null )
rs.close();
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
}
public Board getBoardContent(int sno)
{
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
con = DriverManager.getConnection(ConnectionPoolManager.URL_PREFIX + "testOracle");
// "SELECT sno , vno , top , title , id , content FROM board WHERE sno = ?";
pstmt = con.prepareStatement(VIEW_QUERY);
pstmt.setInt(1,sno);
rs = pstmt.executeQuery();
if ( rs.next() )
{
Board board = new Board();
board.setSno(rs.getInt(1));
board.setVno(rs.getString(2));
board.setTop(rs.getInt(3));
board.setTitle(rs.getString(4));
board.setId(rs.getString(5));
board.setContent(rs.getString(6));
return board;
}
else
return null;
}
catch ( Exception e1 )
{
e1.printStackTrace();
return null;
}
finally
{
try
{
if ( rs != null )
rs.close();
if ( pstmt != null )
pstmt.close();
if ( con != null )
con.close();
}
catch ( Exception ignore )
{
}
}
}
기업100%환급/오라클/자바/스프링/안드로이드/닷넷C#/웹퍼블리싱… | 12-27 | 2163 | ||
[채용예정교육]오라클자바개발잘하는신입뽑기2개월과정,교육전취… | 12-11 | 1562 | ||
53 | [평일주간]100%환급,안드로이드,자바,C#,스프링3.2,SQL,힌트/튜… | 03-15 | 1351 | |
52 | [주말]C#,ASP.NET마스터 | 01-31 | 1468 | |
51 | [기업100%환급,평일주간]SQL기초에서스키마오브젝트,PLSQL,힌트… | 01-31 | 1543 | |
50 | [기업100%환급]Spring ,MyBatis,Hibernate실무과정(스프링개발자… | 01-31 | 1172 | |
49 | [평일주간,평일야간,주말]Spring,MyBatis,Hibernate개발자과정 | 01-19 | 1474 | |
48 | [평일주간,평일야간,주말]안드로이드개발자과정 | 01-11 | 1298 | |
47 | [주말주간,주말야간]JAVA,Network&JSP&Spring,MyBatis,Hibernate | 01-03 | 1803 | |
46 | 기업100%환급/오라클/자바/스프링/안드로이드/닷넷C#/웹퍼블리싱… | 12-27 | 2163 | |
45 | [기업100%환급]자바웹개발기초과정(JAVA,JDBC,JSP,Servlet,Aajx,… | 12-19 | 1564 | |
44 | [평일야간, 주말]웹퍼블리싱 마스터(HTML5,CSS3,jQUERY,AJAX,Jav… | 12-14 | 1543 | |
43 | [채용예정교육]오라클자바개발잘하는신입뽑기2개월과정,교육전취… | 12-11 | 1562 | |
42 | [주말, 평일야간]자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBati… | 12-09 | 1251 | |
41 | [평일야간]닷넷(C#,Network,ADO.NET,ASP.NET)마스터 | 12-01 | 1473 | |
40 | [기업100%환급]자바기초&안드로이드개발자과정(Android전액환급… | 12-01 | 1609 | |
39 | [평일야간,주말]SQL기초에서실무까지(SQL기초,PLSQL,힌트,튜닝) | 12-01 | 1121 |
댓글 없음:
댓글 쓰기