99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
首頁精彩閱讀JDBC之大數(shù)據(jù)內(nèi)容的傳輸_數(shù)據(jù)分析師
JDBC之大數(shù)據(jù)內(nèi)容的傳輸_數(shù)據(jù)分析師
2014-12-14
收藏

JDBC之大數(shù)據(jù)內(nèi)容的傳輸_數(shù)據(jù)分析師

JDBC之 大數(shù)據(jù)內(nèi)容的傳輸

什么是大數(shù)據(jù)內(nèi)容?

      在數(shù)據(jù)庫中,有一條一條的記錄,記錄中很多字段都是幾個字符就夠的,假如現(xiàn)在要把一部小說存入數(shù)據(jù)庫,這本小說當(dāng)然不是幾個字符組成,而是由幾萬字組成,這本小說的數(shù)據(jù)我們就可以說是大數(shù)據(jù),生活中當(dāng)然有各種各樣的大數(shù)據(jù):電影,音樂,圖片等等。。。

大字符數(shù)據(jù)內(nèi)容操作

      大字符內(nèi)容:通常是指很長的字符類型的文件,例如小說,故事等等,內(nèi)容有字符組成。

      下面說明一下MySQL與Oracle中的大數(shù)據(jù)類型

數(shù)據(jù)種類 數(shù)據(jù)大小 MySQL Oracle
字符 char,varchar varchar2
text/longtext clob
字節(jié) bit,blob,longblob blob

1.把大字符數(shù)據(jù)存進(jìn)數(shù)據(jù)庫(把一個文本的數(shù)據(jù)存進(jìn)MySQL中的text類型字段)

@Test public void writeInDB() throws Exception { //獲取連接 connection = sqlUtil.getconnection(); //獲取對象 PreparedStatement preparedStatement = connection.prepareStatement("insert into book values(?)"); //準(zhǔn)備一個Reader用于讀取本地文件 Reader reader = new FileReader(new File("e:/test.txt")); //設(shè)置大數(shù)據(jù)參數(shù) preparedStatement.setClob(1, reader); //執(zhí)行SQL語句  preparedStatement.executeUpdate(); //關(guān)閉資源  reader.close();
    sqlUtil.close(preparedStatement, connection);
} 

2.從數(shù)據(jù)庫把大字符文件讀入到本地

@Test public void readFromDB() throws Exception
{ //獲取連接 connection = sqlUtil.getconnection(); //創(chuàng)建對象 PreparedStatement preparedStatement = connection.prepareStatement("SELECT content FROM book"); //設(shè)置參數(shù)//preparedStatement.setObject(1, "book");//獲得結(jié)果 ResultSet res = preparedStatement.executeQuery(); //以String的形式獲得大字符內(nèi)容 while(res.next())
    {
String content = res.getString("content");
System.out.println(content);
    } //關(guān)閉資源  sqlUtil.close(preparedStatement, connection);
}

      獲得結(jié)果后還有第二種方法:

@Test public void readFromDB() throws Exception
{ //獲取連接 connection = sqlUtil.getconnection(); //創(chuàng)建對象 PreparedStatement preparedStatement = connection.prepareStatement("SELECT content FROM book"); //設(shè)置參數(shù)//preparedStatement.setObject(1, "book");//獲得結(jié)果 ResultSet res = preparedStatement.executeQuery();  FileWriter fileWriter = new FileWriter(new File("d:/11021.txt")); //利用Clob對象 if(res.next())
{
Clob clob = res.getClob("content");
Reader reader = clob.getCharacterStream(); //然后把Reader寫入到本地文件中 char[] cr = new char[1024]; int len = 0; while((len = reader.read(cr))!=-1)
{
fileWriter.write(cr, 0, len);
}
reader.close();
} //關(guān)閉資源 fileWriter.close();
sqlUtil.close(preparedStatement, connection);
}

      以上就是對大字符文件的讀入與寫出~下面我們示范來對大字節(jié)文件的操作~

4.把大字節(jié)文件寫入數(shù)據(jù)庫

 @Test public void writeInDB() throws Exception { //獲取連接 connection = sqlUtil.getconnection(); //獲取對象 PreparedStatement preparedStatement = connection.prepareStatement("insert into book values(?,?)"); //準(zhǔn)備一個InputStream用于讀取本地文件 InputStream in = new FileInputStream(new File("f:/computer.jpg")); //設(shè)置大數(shù)據(jù)參數(shù) preparedStatement.setObject(1, 1);
preparedStatement.setBlob(2, in); //也可以使用這個//preparedStatement.setBinaryStream(2, in);//執(zhí)行SQL語句 preparedStatement.executeUpdate(); //關(guān)閉資源 in.close();
sqlUtil.close(preparedStatement, connection);
    }

5.從數(shù)據(jù)庫把大字節(jié)文件讀取到本地

@Test public void readFromDB() throws Exception
{ //獲取連接 connection = sqlUtil.getconnection(); //創(chuàng)建對象 PreparedStatement preparedStatement = connection.prepareStatement("SELECT content FROM book where id=?"); //設(shè)置參數(shù) preparedStatement.setInt(1, 1); //獲得結(jié)果 ResultSet res = preparedStatement.executeQuery();

FileOutputStream out = new FileOutputStream(new File("d:/999.jpg")); //利用Blob對象 if(res.next())
{ //Blob blob = res.getBlob("content");//InputStream in =  blob.getBinaryStream();//這樣也行  InputStream in = res.getBinaryStream("content"); //然后把Reader寫入到本地文件中 byte[] buf = new byte[1024]; int len = 0; while((len = in.read(buf))!=-1)
{ out.write(buf, 0, len);
} in.close(); out.close();
} //關(guān)閉資源  sqlUtil.close(preparedStatement, connection);
}

數(shù)據(jù)分析咨詢請掃描二維碼

若不方便掃碼,搜微信號:CDAshujufenxi

數(shù)據(jù)分析師資訊
更多

OK
客服在線
立即咨詢
客服在線
立即咨詢
') } function initGt() { var handler = function (captchaObj) { captchaObj.appendTo('#captcha'); captchaObj.onReady(function () { $("#wait").hide(); }).onSuccess(function(){ $('.getcheckcode').removeClass('dis'); $('.getcheckcode').trigger('click'); }); window.captchaObj = captchaObj; }; $('#captcha').show(); $.ajax({ url: "/login/gtstart?t=" + (new Date()).getTime(), // 加隨機(jī)數(shù)防止緩存 type: "get", dataType: "json", success: function (data) { $('#text').hide(); $('#wait').show(); // 調(diào)用 initGeetest 進(jìn)行初始化 // 參數(shù)1:配置參數(shù) // 參數(shù)2:回調(diào),回調(diào)的第一個參數(shù)驗(yàn)證碼對象,之后可以使用它調(diào)用相應(yīng)的接口 initGeetest({ // 以下 4 個配置參數(shù)為必須,不能缺少 gt: data.gt, challenge: data.challenge, offline: !data.success, // 表示用戶后臺檢測極驗(yàn)服務(wù)器是否宕機(jī) new_captcha: data.new_captcha, // 用于宕機(jī)時表示是新驗(yàn)證碼的宕機(jī) product: "float", // 產(chǎn)品形式,包括:float,popup width: "280px", https: true // 更多配置參數(shù)說明請參見:http://docs.geetest.com/install/client/web-front/ }, handler); } }); } function codeCutdown() { if(_wait == 0){ //倒計(jì)時完成 $(".getcheckcode").removeClass('dis').html("重新獲取"); }else{ $(".getcheckcode").addClass('dis').html("重新獲取("+_wait+"s)"); _wait--; setTimeout(function () { codeCutdown(); },1000); } } function inputValidate(ele,telInput) { var oInput = ele; var inputVal = oInput.val(); var oType = ele.attr('data-type'); var oEtag = $('#etag').val(); var oErr = oInput.closest('.form_box').next('.err_txt'); var empTxt = '請輸入'+oInput.attr('placeholder')+'!'; var errTxt = '請輸入正確的'+oInput.attr('placeholder')+'!'; var pattern; if(inputVal==""){ if(!telInput){ errFun(oErr,empTxt); } return false; }else { switch (oType){ case 'login_mobile': pattern = /^1[3456789]\d{9}$/; if(inputVal.length==11) { $.ajax({ url: '/login/checkmobile', type: "post", dataType: "json", data: { mobile: inputVal, etag: oEtag, page_ur: window.location.href, page_referer: document.referrer }, success: function (data) { } }); } break; case 'login_yzm': pattern = /^\d{6}$/; break; } if(oType=='login_mobile'){ } if(!!validateFun(pattern,inputVal)){ errFun(oErr,'') if(telInput){ $('.getcheckcode').removeClass('dis'); } }else { if(!telInput) { errFun(oErr, errTxt); }else { $('.getcheckcode').addClass('dis'); } return false; } } return true; } function errFun(obj,msg) { obj.html(msg); if(msg==''){ $('.login_submit').removeClass('dis'); }else { $('.login_submit').addClass('dis'); } } function validateFun(pat,val) { return pat.test(val); }