clob에 자료 넣기.
2011-02-06 03:35:11

Clob에 저장하기

1: import java.sql.*;

2: import java.io.*;

3: import oracle.sql.*;

4: import oracle.jdbc.driver.*;

5: ...

6:

7: public void insertQuery(UploadBoard up,int re_step,int re_level)

throws Exception

8: {

9: ResultSet rs = null;

10: PreparedStatement pstmt = null;

11: Connection conn = null;

12: String query = "insert into "+up.getTableName()+" (seq,re_step,

re_level,name,title,pwd,email,readnum,writeday,ip,relativeCnt,

homepage,imgInfo,content,tag)

values(?,?,?,?,?,?,?,0,sysdate,?,0,?,?,empty_clob(),?)";

오라클 명령어 empty_clob()을 이용해 공간을 확보한다.

13: try{

14: conn = DBManager.getClobConnection();

15: conn.setAutoCommit(false);

CLOB column을 업데이트 하는동안 다른 process의 접근을 막기위해

setAutoCommit(false)를 반드시 설정해야 한다. 이부분이 가장 중요하다.

16: pstmt = conn.prepareStatement(query);

17: pstmt.setInt(1,up.getSeq());

18: pstmt.setInt(2,re_step);

19: pstmt.setInt(3,re_level);

20: pstmt.setString(4,up.getName());

21: pstmt.setString(5,up.getTitle());

22: pstmt.setString(6,up.getPwd());

23: pstmt.setString(7,up.getEmail());

24: pstmt.setString(8,up.getIp());

25: pstmt.setString(9,up.getHomepage());

26: pstmt.setString(10,up.getImgInfo());

27: pstmt.setString(11,up.getTag());

28: pstmt.executeUpdate();

29: pstmt.close();

30: String query2 = " select /*+ index_desc("+up.getTableName()+

" "+up.getTableName()+"_indx) */ content from "+

up.getTableName()+" where seq = ? for update ";

for update를 이용해 CLOB column을 lock한다.

31: pstmt = conn.prepareStatement(query2);

32: pstmt.setInt(1,up.getSeq());

33: rs = pstmt.executeQuery();

34: if(rs.next()) {

35: CLOB clob = ((OracleResultSet)rs).getCLOB(1);

36: Writer writer = clob.getCharacterOutputStream();

37: Reader src = new CharArrayReader(up.getContent().toCharArray());

38: char[] buffer = new char[1024];

39: int read = 0;

40: while ( (read = src.read(buffer,0,1024)) != -1) {

41: writer.write(buffer, 0, read); // write clob.

42: }

43: src.close();

44: writer.close();

45: }

46: conn.commit();

47: conn.setAutoCommit(true);

CLOB column에 데이터을 저장하였다면 commit()을 실행시키고

conn.setAutoCommit(true)로 다시 설정한다.

48: }finally{

49: DBManager.close(rs,pstmt,conn);

50: }

51: }

Clob 불러오기

...

1: public BoardTable getViewData(String tableName,int seq) throws Exception

2: {

3: BoardTable bTable = new BoardTable();

4: String query = " select * from "+tableName+" where seq = ? ";

5: ResultSet rs = null;

6: PreparedS\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0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\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0tatement pstmt = null;

7: Connection conn = null;

8: try{

9: conn = DBManager.getConnection();

10: pstmt = conn.prepareStatement(query);

11: pstmt.setInt(1,seq);

12: rs = pstmt.executeQuery();

13: if (rs.next()) {

14: ...

15: ...

16: StringBuffer output = new StringBuffer();

17: Reader input = rs.getCharacterStream("content");

18: char[] buffer = new char[1024];

19: int byteRead;

20: while((byteRead=input.read(buffer,0,1024))!=-1){

21: output.append(buffer,0,byteRead);

22: }

23: input.close();

24: bTable.setContent(output.toString());

CLOB 데이터를 불러오기 위해서는 위에서처럼

rs.getCharacterStream("content")로 불러서 StringBuffer에 담아야 한다.

25: ...

26: ...

27: }

28: } finally {

29: DBManager.close(rs,pstmt,conn);

30: }

31: return bTable;

32: }

문서에 대하여

- 작성자 : 김정식 (oramaster _at_ naver.com)

- 작성일 : 2005-10-11

- 강좌 URL : http://www.oracleclub.com/lecture/1870

- 이 문서를 다른 블로그나 홈페이지에 게재하실 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^

- 오라클클럽의 모든 강좌는 크리에이티브 커먼즈의 저작자표시-비영리-동일조건변경허락(BY-NC-SA) 라이선스에 따라 자유롭게 사용할 수 있습니다.

▼ more
Twitter App on iPhone
2011-02-05 21:16:57

드디어,

기능 구현 실제 부.

1. Table refresh

2. Grouping Table.

3. Using sqllite

4. Twitter

5. View and 형재형 url..

▼ more
음; 이 에러는.. iphone
2011-02-05 20:09:14

2011-02-05 20:08:13.310 Nav[1182:207] Here~!

2011-02-05 20:08:13.316 Nav[1182:207] *** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView.m:5613

2011-02-05 20:08:13.318 Nav[1182:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

*** Call stack at first throw:

(

0 CoreFoundation 0x00db0be9 __exceptionPreprocess + 185

1 libobjc.A.dylib 0x00f055c2 objc_exception_throw + 47

2 CoreFoundation 0x00d69628 +[NSException raise:format:arguments:] + 136

3 Foundation 0x000b447b -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116

4 UIKit 0x0032d8f3 -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] + 883

5 UIKit 0x0032377f -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] + 75

6 UIKit 0x00338450 -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] + 1561

7 UIKit 0x00330538 -[UITableView layoutSubviews] + 242

8 QuartzCore 0x01c6e451 -[CALayer layoutSublayers] + 181

9 QuartzCore 0x01c6e17c CALayerLayoutIfNeeded + 220

10 QuartzCore 0x01c6737c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310

11 QuartzCore 0x01c670d0 _ZN2CA11Transaction6commitEv + 292

12 QuartzCore 0x01c977d5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 99

13 CoreFoundation 0x00d91fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27

14 CoreFoundation 0x00d270e7 __CFRunLoopDoObservers + 295

15 CoreFoundation 0x00cefbd7 __CFRunLoopRun + 1575

16 CoreFoundation 0x00cef240 CFRunLoopRunSpecific + 208

17 CoreFoundation 0x00cef161 CFRunLoopRunInMode + 97

18 GraphicsServices 0x016e5268 GSEventRunModal + 217

19 GraphicsServices 0x016e532d GSEventRun + 115

20 UIKit 0x002c842e UIApplicationMain + 1160

21 Nav 0x00001c48 main + 102

22 Nav 0x00001bd9 start + 53

)

terminate called after throwing an instance of 'NSException'

▼ more
재회
2011-02-05 09:02:34

1시 이천도착

[경민] - 준비물 : 건전지AA 1EA, 노트북

12시 이천출발

1시 재회

5시정도까지 고구마로 가도 되고 피곤하면 안가도 되고,

그 다음 교보문고..

▼ more