stream

웹페이지를 크롤링해보자.
IOException
URL url = null;
String address = “http://pamtree.tistory.com“;
try {
 BufferedReader input  = new BufferedReader(new InputStreamReader(url.openStream()) );
 while ( (line=input.readLine()) != null ) {
  System.out.println(line);
 }
}


 


키보드 입력을 받아보자.
IOException
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String  = input.readLine();


 


파일 입력을 받아보자.

Blob->String
ResultSet rs = null;
rs = stmt.executeQuery(query);
Blob blob = rs.getBlob(“sentence”);
byte[] bytes = blob.getBytes(1, (int) blob.length());
sentence = new String(bytes);

String->Blob
PreparedStatement pstmt = conn.prepareStatement(query);
byte[] bytes = item.getSentence().getBytes();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
pstmt.setBinaryStream(4, bais, bytes.length);
pstmt.executeQuery();
pstmt.close();

Clob->String
//CLOB clob = ((OracleResultSet)rs).getCLOB(1);
oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob(“doc_content”);
clob.putString(1, bean.getDoc_content());
sql=”UPDATE document SET doc_content = ? WHERE doc_no = ? “;
PreparedStatement pstmt1 = conn.prepareStatement(sql);
pstmt1.setClob(1, clob);
pstmt1.setString(2, bean.getDoc_no());
pstmt1.executeUpdate();
pstmt1.close();

String->Clob
StringBuffer output = new StringBuffer();
Reader input = rs.getCharacterStream(“doc_content”);
char[] buffer = new char[1024];
int byteRead;
while((byteRead=input.read(buffer,0,1024)) != -1){
 output.append(buffer,0,byteRead);
 System.out.println(byteRead);
}
input.close();
bean.setDoc_content(output.toString());

Leave a Reply

Your email address will not be published. Required fields are marked *