write picture to oracle using java
import java.sql.*;
import java.io.*;
public class Blobtest {
public Blobtest() {
}
public static void main (String args [])
throws SQLException, IOException
{
write();
//read();
}
static void read() throws SQLException, IOException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@ebizser:1521:serverdb", "scott", "tiger");
conn.setAutoCommit (false);
Statement stmt = conn.createStatement ();
ResultSet rset =
stmt.executeQuery ("select col2 from lobtest where userid=1");
if (rset.next ())
{
InputStream gif_data = rset.getBinaryStream (1);
FileOutputStream os = new FileOutputStream ("example.jpe");
int c;
while ((c = gif_data.read ()) != -1)
os.write (c);
os.close ();
}
if (rset != null)
rset.close();
if (stmt != null)
stmt.close();
if (conn != null)
conn.close();
}
static void write() throws SQLException, IOException {
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
Connection conn =
DriverManager.getConnection ("jdbc:oracle:oci8:@oralihj", "yssj", "misd");
conn.setAutoCommit (false);
File file = new File("C:1.jpg");
InputStream is = new FileInputStream ("C:1.jpg");
PreparedStatement pstmt =
conn.prepareStatement ("insert into pic (id, pic ) values (?, ?)");
pstmt.setBinaryStream(2, is, (int)file.length ());
pstmt.setInt (1, 2);
pstmt.execute ();
if (pstmt != null)
pstmt.close();
if (conn != null)
conn.close();
}
}
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9879835/viewspace-996783/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- picture
- ORACLE等待事件:direct path writeOracle事件
- Oracle db file parallel write 和 log file parallel write 等待事件 說明OracleParallel事件
- Using Oracle SecureFiles LOBsOracle
- How to write a custom classloader in javaJava
- Using Regular Expressions in Oracle DatabaseExpressOracleDatabase
- Oracle - ORA-09817: Write to audit file failedOracleAI
- [轉載]Oracle等待事件Data file init writeOracle事件
- using escape character whitin oracleOracle
- Java 中的寫時複製 (Copy on Write, COW)Java
- MySQL的double write和Oracle對比學習MySqlOracle
- No read or write permission to ORACLE_HOME/.patch_storageOracle
- Using Morphia to map Java objects in MongoDBJavaObjectMongoDB
- Using WebLogic Server With Oracle RAC(轉)WebServerOracle
- oracle JRE issue using runInstallerOracle
- Using Create directory & UTL_FILE in OracleOracle
- For oracle databases, if the top showing the oracle database, then oracle process is using the top cOracleDatabase
- oracle10g_11g process程式及sga元件體系架構圖pictureOracle元件架構
- 【TUNE_ORACLE】等待事件之IO等待“direct path write”Oracle事件
- Oracle常見等待事件之direct path read/writeOracle事件
- 【蓋國強】Oracle Wait Event:Data file init writeOracleAI
- How To Using Flashback Data Archive (Oracle Total Recall)HiveOracle
- Oracle 12c: Recover tables using RMANOracle
- How to check whether the current database in using Oracle optionsDatabaseOracle
- 【SQL】Using Oracle's Parallel Execution FeaturesSQLOracleParallel
- Step by Step Data Replication Using Oracle GoldenGateOracleGo
- watchOS 學習筆記 | Big Picture筆記
- WPF image show web picture via url and converterWeb
- How to write event log(Event Viewer) using C++ - 用C++如何寫事件日誌(事件檢視器)ViewC++事件
- 【TUNE_ORACLE】等待事件之IO等待“db file parallel write”Oracle事件Parallel
- 【TUNE_ORACLE】等待事件之IO等待“direct path write temp”Oracle事件
- 【TUNE_ORACLE】等待事件之日誌等待“log file parallel write”Oracle事件Parallel
- 關於Cache的write-through & write-back
- MySQL double writeMySql
- hio_write
- [Javascript] Write .call()JavaScript
- Oracle 12Cr2 Using CloneDB to clone a databaseOracleDatabase
- zt_Using Oracle's Parallel Execution FeaturesOracleParallel