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

📄 longexample1.java

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

/**
 * @author Sean
 * @version 1.0
 * @date  2005.8.25
 */
public class LongExample1 {
	public static void writeLong(Connection conn,String fileName) throws SQLException, IOException {		
		File myFile = new File(fileName);
		InputStream in = new FileInputStream(myFile);
		
		int length = (int)myFile.length();
		                     
		PreparedStatement ps = conn.prepareStatement("insert into long_content values(?,?)");
		
		ps.setString(1,fileName);
		ps.setAsciiStream(2,in,length);
		
		ps.execute();
		
		conn.commit();
		
		in.close();
		ps.close();
		
		System.out.println("Wrote Long from file "+fileName+" to Long");
	} 
	
	public static void writeLongRaw(Connection conn,String fileName) throws SQLException,IOException {
		File myFile = new File(fileName);
		int length = (int)myFile.length();
		
		InputStream in = new FileInputStream(myFile);
		
	  PreparedStatement ps = conn.prepareStatement("insert into long_raw_content values(?,?)");
	  
	  ps.setString(1,fileName);
	  ps.setBinaryStream(2,in,length);
	  
	  ps.execute();
	  
	  conn.commit();
	  
	  ps.close();
	  in.close();
	  
	  System.out.println("Wrote Long Raw from file "+fileName +" to LONG RAW");
	}
	
	public static void main(String [] args) throws SQLException ,IOException {
		DriverManager.registerDriver(new OracleDriver());
		Connection conn = DriverManager.getConnection("jdbc:oracle:thin:swatt/swgood@10.10.10.251:1521:test");
		conn.setAutoCommit(false);
		
		String sourceDirectory = "D:\\JSPBook\\JDBC\\JDBC_book\\sample_files\\";
		
		writeLong(conn,sourceDirectory + "textContent.txt");
		writeLongRaw(conn,sourceDirectory + "pxt.jpg");
		
		conn.close();
	}
}

⌨️ 快捷键说明

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