<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    深藍(lán)的天空下,有你有我...
    共享酸、甜、苦、辣
    posts - 23,comments - 19,trackbacks - 0
    mysql 大對象存取: 類型一般應(yīng)該用mediumblod, blob只能存2的16次方個byte, mediumblod是24次方, 一般來說夠用了.longblob是32次方有些大. MYSQL默認(rèn)配置只能存1M大小的文件,要修改配置,WIN版本的在mysql.ini文件中 修改max_allowed_packet,net_buffer_length等幾個參數(shù),或直接SET GLOBAL varName=value. linux版本可以在啟動參數(shù)后加-max_allowed_packet=xxM等幾個參數(shù). MYSQL存大對象最好直接就setBinaryStream,又快又方便. 而不要先插入空再造型成BLOB然后再setBlob 例子: import java.sql.*; import java.io.*; public class DBTest { static String driver = "org.gjt.mm.mysql.Driver"; static String url = "jdbc:mysql://localhost:3306/test"; static String user = "root"; static String passwd = "passwd"; public static void main(String[] args) throws Exception { Connection conn = null; try { Class.forName(driver); conn = DriverManager.getConnection(url,user,passwd); int op = 1; //插入 if (op == 0) { PreparedStatement ps = conn.prepareStatement("insert into tb_file values (?,?)"); ps.setString(1, "aaa.exe"); InputStream in = new FileInputStream("d:/aaa.exe"); ps.setBinaryStream(2,in,in.available()); ps.executeUpdate(); ps.close(); } else { //取出 PreparedStatement ps = conn.prepareStatement("select * from tb_file where filename = ?"); ps.setString(1, "aaa.exe"); ResultSet rs = ps.executeQuery(); rs.next(); InputStream in = rs.getBinaryStream("filecontent"); System.out.println(in.available()); FileOutputStream out = new FileOutputStream("d:/bbb.exe"); byte[] b = new byte[1024]; int len = 0; while ( (len = in.read(b)) != -1) { out.write(b, 0, len); out.flush(); } out.close(); in.close(); rs.close(); ps.close(); } } catch (Exception ex) { ex.printStackTrace(System.out); } finally { try {conn.close();} catch (Exception ex) { } } } } sqlserver 大對象存取沒有什么多說的,只要是image類型就行了,注意這是column類型,有人以為它只能存 圖象.image是文件鏡象的意思. import java.sql.*; import java.io.*; public class DBTest { static String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; static String url = "jdbc:microsoft:sqlserver://192.168.0.202:9999999999;DatabaseName=dddd"; static String user = "sa"; static String passwd = "ps"; public static void main(String[] args) throws Exception { Connection conn = null; try { Class.forName(driver); conn = DriverManager.getConnection(url,user,passwd); int op = 0; //插入 if (op == 0) { PreparedStatement ps = conn.prepareStatement("insert into tb_file values (?,?)"); ps.setString(1, "aaa.exe"); InputStream in = new FileInputStream("d:/aaa.exe"); ps.setBinaryStream(2,in,in.available()); ps.executeUpdate(); ps.close(); } else { //取出 PreparedStatement ps = conn.prepareStatement("select * from tb_file where filename = ?"); ps.setString(1, "aaa.exe"); ResultSet rs = ps.executeQuery(); rs.next(); InputStream in = rs.getBinaryStream("filecontent"); System.out.println(in.available()); FileOutputStream out = new FileOutputStream("d:/bbb.exe"); byte[] b = new byte[1024]; int len = 0; while ( (len = in.read(b)) != -1) { out.write(b, 0, len); out.flush(); } out.close(); in.close(); rs.close(); ps.close(); } } catch (Exception ex) { ex.printStackTrace(System.out); } finally { try {conn.close();} catch (Exception ex) { } } } } ORACLE的大對象存儲有些變態(tài),要無論是Blob,還是CLOB都要求先插入一個空值,然后 查詢并鎖定這一條記錄,獲取對Lob的引用再進(jìn)行填充,網(wǎng)上有太多的例子.我個人認(rèn)為 這種方法垃圾得連寫都不想寫了,你可以自己去搜索一下. 這種特別的操作既增加操作的復(fù)雜度,又違反了JDBC接口的規(guī)范,所以我極力反對這樣 使用,如果你和我有同樣的觀點(diǎn).那么我提供另一種通用的方法.就是你不用LOB而用 oracle的LONG RAW來代替它們.這樣就可以象其它對象一樣操作了: create table tb_file(filename varchar2(255),filecontent LONG RAW); import java.sql.*; import java.io.*; public class BlobTest { static String driver = "oracle.jdbc.driver.OracleDriver"; static String url = "jdbc:oracle:thin:@localhost:1521:test"; static String user = "system"; static String passwd = "passwd"; public static void main(String[] args) throws Exception { Connection conn = null; try { Class.forName(driver); conn = DriverManager.getConnection(url, user, passwd); int op = 1; //插入 if (op == 0) { PreparedStatement ps = conn.prepareStatement("insert into tb_file values (?,?)"); ps.setString(1, "aaa.exe"); InputStream in = new FileInputStream("d:/aaa.exe"); ps.setBinaryStream(2,in,in.available()); ps.executeUpdate(); ps.close(); } else { //取出 PreparedStatement ps = conn.prepareStatement("select * from tb_file where filename = ?"); ps.setString(1, "aaa.exe"); ResultSet rs = ps.executeQuery(); rs.next(); InputStream in = rs.getBinaryStream("filecontent"); System.out.println(in.available()); FileOutputStream out = new FileOutputStream("d:/bbb.exe"); byte[] b = new byte[1024]; int len = 0; while ( (len = in.read(b)) != -1) { out.write(b, 0, len); out.flush(); } out.close(); in.close(); rs.close(); ps.close(); } } catch (Exception ex) { ex.printStackTrace(System.out); } finally { try { conn.close(); } catch (Exception ex) {} } } } 轉(zhuǎn)自:http://dev.csdn.net/author/axman/1ca2ede425e44dba9ac20c2e262e4fb8.html
    posted on 2011-06-19 02:02 三刀流の逆風(fēng) 閱讀(254) 評論(0)  編輯  收藏 所屬分類: JAVA
    主站蜘蛛池模板: 6080午夜一级毛片免费看6080夜福利| 亚洲视频在线观看免费| 1000部国产成人免费视频| 亚洲精品自产拍在线观看| 日日狠狠久久偷偷色综合免费| 日本免费一区二区三区最新vr| 色婷五月综激情亚洲综合| 亚洲精品在线免费观看视频| 亚洲性一级理论片在线观看| 18成禁人视频免费网站| 亚洲另类古典武侠| 国产在线a免费观看| 精品亚洲国产成人| 日本免费中文字幕在线看| 老司机精品视频免费| 中文字幕亚洲专区| 国产午夜精品久久久久免费视| 久久精品国产亚洲AV电影| 91频在线观看免费大全| 亚洲免费网站观看视频| 国产又大又黑又粗免费视频| 一级一片免费视频播放| 亚洲成在人线av| 日韩在线播放全免费| 亚洲中文字幕乱码AV波多JI| 全部免费毛片免费播放| 中文字幕免费播放| 亚洲制服在线观看| 免费a级毛片大学生免费观看 | 0588影视手机免费看片| 亚洲色欲啪啪久久WWW综合网| 免费真实播放国产乱子伦| 久久久精品视频免费观看| 亚洲欧洲日产国码久在线观看| 一区二区无码免费视频网站| 另类小说亚洲色图| 亚洲人成在线播放网站| 成人免费黄色网址| 免费在线人人电影网| 亚洲精品高清国产一线久久| 成人免费毛片内射美女-百度|