⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 longexample2.java

📁 Connection Oracle9i database Read and Wrote Lob ,long or long raw type and save to file
💻 JAVA
字号:
import java.io.*;
import java.sql.*;

/**
 * Read Oracle database variance Long and Long Raw
 * @author Sean
 * @version 1.0
 */
public class LongExample2 {
	public static void readLong(Statement stmt,String fileName,
	                            String targetDirectory) throws SQLException,IOException {
	  ResultSet rs = stmt.executeQuery("select long_column from long_content");
	  rs.next();
	  InputStream in = rs.getAsciiStream(1);
	  
	  String saveName = targetDirectory + "readLong"+fileName;
	  saveFile(in,saveName);
	  
	  in.close();
	  
	  System.out.println("Read Long and saved file "+saveName);
	}
	
	public static void readLongRaw(Statement stmt,String fileName,String targetDirectory) throws SQLException,IOException {
		ResultSet rs = stmt.executeQuery("select long_raw_column from long_raw_content ");
		rs.next();
		InputStream in = rs.getBinaryStream(1);
		String saveName = targetDirectory + "readLongRaw"+fileName;
		saveFile(in,saveName);
		
		in.close();
		
		System.out.println("Read Long Raw and saved file "+saveName);
	}
	
	public static void saveFile(InputStream in,String fileName) throws IOException {
	  FileOutputStream out = new FileOutputStream(
	                         new File(fileName));
	  byte[] byteBuffer = new byte[8132];
	  int byteRead;
	  while((byteRead = in.read(byteBuffer)) != -1 ) {
	  	out.write(byteBuffer);
	  }
	  out.close();
	}
	
	public static void main(String[] args) throws SQLException,IOException {
		DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@10.10.10.251:1521:test","swatt","swgood");
		conn.setAutoCommit(false);
		Statement stmt = conn.createStatement();
		
		String targetDirectory = "D:\\JSPBook\\JDBC\\JDBC_book\\";
		readLong(stmt,"textContent.txt",targetDirectory);
		readLongRaw(stmt,"pxt.jpg",targetDirectory);
		
		stmt.close();
		conn.close();
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -