0
A
回答
0
你好,請閱讀下面的帖子和this Link將有助於
此示例演示了Oracle JDBC BFILE的支持。它示出了填充BFILES的表,並且包括用於傾倒BFILE的內容的實用程序。有關BFILE的信息。
/*
* This sample demonstrate basic File support
*/
import java.sql.*;
import java.io.*;
import java.util.*;
//including this import makes the code easier to read
import oracle.jdbc.driver.*;
// needed for new BFILE class
import oracle.sql.*;
public class FileExample{
public static void main (String args [])throws Exception{
// Register the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
//
// The sample creates a DIRECTORY and you have to be connected as
// "system" to be able to run the test.
// I you can't connect as "system" have your system manager
// create the directory for you, grant you the rights to it, and
// remove the portion of this program that drops and creates the directory.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@", "system", "manager");
// It's faster when auto commit is off
conn.setAutoCommit (false);
// Create a Statement
Statement stmt = conn.createStatement();
try
{
stmt.execute ("drop directory TEST_DIR");
}
catch (SQLException e)
{
// An error is raised if the directory does not exist. Just ignore it.
}
stmt.execute ("create directory TEST_DIR as '/tmp/filetest'");
try
{
stmt.execute ("drop table test_dir_table");
}
catch (SQLException e)
{
// An error is raised if the table does not exist. Just ignore it.
}
// Create and populate a table with files
// The files file1 and file2 must exist in the directory TEST_DIR created
// above as symbolic name for /private/local/filetest.
stmt.execute ("create table test_dir_table (x varchar2 (30), b bfile)");
stmt.execute ("insert into test_dir_table values
('one', bfilename ('TEST_DIR', 'file1'))");
stmt.execute ("insert into test_dir_table values
('two', bfilename ('TEST_DIR', 'file2'))");
// Select the file from the table
ResultSet rset = stmt.executeQuery ("select * from test_dir_table");
while (rset.next())
{
String x = rset.getString (1);
BFILE bfile = ((OracleResultSet)rset).getBFILE (2);
System.out.println (x + " " + bfile);
// Dump the file contents
dumpBfile (conn, bfile);
}
// Close all resources
rset.close();
stmt.close();
conn.close();}
// Utility function to dump the contents of a Bfile
static void dumpBfile (Connection conn, BFILE bfile) throws Exception{
System.out.println ("Dumping file " + bfile.getName());
System.out.println ("File exists: " + bfile.fileExists());
System.out.println ("File open: " + bfile.isFileOpen());
System.out.println ("Opening File: ");
bfile.openFile();
System.out.println ("File open: " + bfile.isFileOpen());
long length = bfile.length();
System.out.println ("File length: " + length);
int chunk = 10;
InputStream instream = bfile.getBinaryStream();
// Create temporary buffer for read
byte[] buffer = new byte[chunk];
// Fetch data
while ((length = instream.read(buffer)) != -1)
{
System.out.print("Read " + length + " bytes: ");
for (int i=0; i<length; i++)
System.out.print(buffer[i]+" ");
System.out.println();
}
// Close input stream
instream.close();
// close file handler
bfile.closeFile();}}
0
使用下面的鏈接
https://docs.oracle.com/cd/A97335_02/apps.102/a83724/oralob3.htm#1059336
在那裏,你會發現這樣的
OraclePreparedStatement ops = (OraclePreparedStatement)conn.prepareStatement
("INSERT INTO my_bfile_table VALUES (?,?)");
ops.setString(1,"one");
ops.setBFILE(2, bfile);
ops.execute();
許多例子
相關問題
- 1. 讀取java中的XML數據庫列
- 2. 使用POI讀取Java數據庫(CLOB列)中的Excel數據
- 3. 使用java從mysql數據庫讀取數據
- 4. 具有數據庫的Java Applet
- 5. 用於讀取數據庫模式的Java庫
- 6. SQL使用數據讀取器從數據庫問題讀取
- 7. 在Linux上使用什麼數據庫工具來讀取/ 400數據庫?
- 8. Java:如何有效地從數據庫中讀取?
- 9. Sqlite3沒有從數據庫中讀取
- 10. 從現有數據庫中讀取Grails
- 11. 從文件讀取具有在Java
- 12. 在Java中讀取數據
- 13. 無法讀取數據庫
- 14. Oracle數據庫讀取鎖
- 15. PHP讀取和數據庫
- 16. 錯誤讀取數據庫
- 17. 無法讀取數據庫
- 18. Ajax從數據庫讀取
- 19. PDO從數據庫讀取
- 20. vb.net - 讀取數據庫
- 21. 的Java:從InputStream讀取數據,並不總是讀取數據
- 22. 從java數據庫讀取docx文件在java中
- 23. 用Java讀取不同的數據庫表
- 24. 用java netbeans的我無法從數據庫讀取
- 25. 使用java讀取數據庫中的xls文件
- 26. 使用java讀取SQLite數據庫文件
- 27. 在寫入數據庫時使用java讀取tcp流
- 28. 使用.Net從Oracle數據庫讀取數據比使用Java快10倍
- 29. SQLite從數據庫讀取數據
- 30. MongoDB從數據庫中讀取數據