이번엔 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 )
{
}
}
}
오라클자바커뮤니티교육센터, 개발자전문교육, 개인80%환급
www.oraclejavacommunity.com
평일주간(9:30~18:10) 개강
(7/14)[기업100%환급]C#4.0,WinForm,ADO.NET프로그래밍
(7/14)[기업100%환급]SQL기초에서 Schema Object까지
(7/14)[기업100%환급]안드로이드개발자과정
(7/21)[기업100%환급]자바기초에서 JDBC, Servlet/JSP까지
(7/21)[기업100%환급]Spring ,MyBatis,Hibernate실무과정
(7/21)[기업100%환급]PL/SQL,ORACLE HINT,TUNING
(7/21)[채용예정교육]오라클자바개발잘하는신입뽑기프로젝트,교육전취업확정
평일야간(19:00~21:50) 개강
(7/09)닷넷(C#,Network,ADO.NET,ASP.NET)마스터과정
(7/10)JAVA,Network&WEB&Framework(자바기초에서웹스프링까지)
(7/15)SQL기초에서실무까지
(7/15)안드로이드개발자과정
(7/16)Spring3.X, MyBatis, Hibernate실무과정
(7/21)웹퍼블리싱 마스터
(7/22)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
(7/22)MyBatis3.X, Hibernate4.X ORM실무과정
주말(10:00~17:50) 개강
(7/12)SQL초보에서 Schema Object까지
(7/12)개발자를위한PLSQL,SQL튜닝,힌트
(7/13)C#,ASP.NET마스터
(7/19)JAVA,Network&WEB&Framework(자바기초에서웹스프링까지)
(7/19)Spring3.X, MyBatis, Hibernate실무과정
(7/19)웹퍼블리싱 마스터
(7/19)안드로이드개발자과정
(7/26)MyBatis3.X, Hibernate4.X ORM실무과정
(8/09)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
주말저녁(18:30~22:20) 개강
(8/02)JAVA,Network&WEB&Framework
(8/09)SQL기초에서실무까지
www.oraclejavacommunity.com
평일주간(9:30~18:10) 개강
(7/14)[기업100%환급]C#4.0,WinForm,ADO.NET프로그래밍
(7/14)[기업100%환급]SQL기초에서 Schema Object까지
(7/14)[기업100%환급]안드로이드개발자과정
(7/21)[기업100%환급]자바기초에서 JDBC, Servlet/JSP까지
(7/21)[기업100%환급]Spring ,MyBatis,Hibernate실무과정
(7/21)[기업100%환급]PL/SQL,ORACLE HINT,TUNING
(7/21)[채용예정교육]오라클자바개발잘하는신입뽑기프로젝트,교육전취업확정
평일야간(19:00~21:50) 개강
(7/09)닷넷(C#,Network,ADO.NET,ASP.NET)마스터과정
(7/10)JAVA,Network&WEB&Framework(자바기초에서웹스프링까지)
(7/15)SQL기초에서실무까지
(7/15)안드로이드개발자과정
(7/16)Spring3.X, MyBatis, Hibernate실무과정
(7/21)웹퍼블리싱 마스터
(7/22)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
(7/22)MyBatis3.X, Hibernate4.X ORM실무과정
주말(10:00~17:50) 개강
(7/12)SQL초보에서 Schema Object까지
(7/12)개발자를위한PLSQL,SQL튜닝,힌트
(7/13)C#,ASP.NET마스터
(7/19)JAVA,Network&WEB&Framework(자바기초에서웹스프링까지)
(7/19)Spring3.X, MyBatis, Hibernate실무과정
(7/19)웹퍼블리싱 마스터
(7/19)안드로이드개발자과정
(7/26)MyBatis3.X, Hibernate4.X ORM실무과정
(8/09)자바기초에서JSP,Ajax,jQuery,Spring3.2,MyBatis까지
주말저녁(18:30~22:20) 개강
(8/02)JAVA,Network&WEB&Framework
(8/09)SQL기초에서실무까지
댓글 없음:
댓글 쓰기