?? readerblobdata.java
字號(hào):
package com;
import java.io.*;
import java.sql.*;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2009-2-26
* Time: 15:30:02
* To change this template use File | Settings | File Templates.
*/
public class ReaderBlobData {
public static void main(String args[]) {
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.1.148:1521:orcl102g", "xux", "xux");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from teacher where tid=1");
InputStream is = null;
while (rs.next()) {
is = rs.getBinaryStream(5);
}
FileOutputStream fos = new FileOutputStream("D:\\3.jpg");
byte[] b = new byte[6200];
is.read(b);
fos.write(b);
} catch (ClassNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (SQLException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (FileNotFoundException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
} catch (IOException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
// 想數(shù)據(jù)庫(kù)中插入blob類型的數(shù)據(jù)如圖片
/* public static void main(String args[]) throws Exception
{
File f = new File("b.jpg");
long length = f.length();
FileInputStream fis = new FileInputStream("b.jpg");
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ora9i","scott","tiger");
PreparedStatement pstmt = conn.prepareStatement("insert into image values(?,?,?)");
pstmt.setString(1,"b.jpg");
pstmt.setInt(2,(int)length);
pstmt.setBinaryStream(3,fis,(int)length);
pstmt.executeUpdate();
pstmt.close();
conn.close();
} */
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -