
在數(shù)據(jù)庫中,有一條一條的記錄,記錄中很多字段都是幾個字符就夠的,假如現(xiàn)在要把一部小說存入數(shù)據(jù)庫,這本小說當(dāng)然不是幾個字符組成,而是由幾萬字組成,這本小說的數(shù)據(jù)我們就可以說是大數(shù)據(jù),生活中當(dāng)然有各種各樣的大數(shù)據(jù):電影,音樂,圖片等等。。。
大字符內(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 |
@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); }
@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é)文件的操作~
@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); }
@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
LSTM 模型輸入長度選擇技巧:提升序列建模效能的關(guān)鍵? 在循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)家族中,長短期記憶網(wǎng)絡(luò)(LSTM)憑借其解決長序列 ...
2025-07-11CDA 數(shù)據(jù)分析師報(bào)考條件詳解與準(zhǔn)備指南? ? 在數(shù)據(jù)驅(qū)動決策的時代浪潮下,CDA 數(shù)據(jù)分析師認(rèn)證愈發(fā)受到矚目,成為眾多有志投身數(shù) ...
2025-07-11數(shù)據(jù)透視表中兩列相乘合計(jì)的實(shí)用指南? 在數(shù)據(jù)分析的日常工作中,數(shù)據(jù)透視表憑借其強(qiáng)大的數(shù)據(jù)匯總和分析功能,成為了 Excel 用戶 ...
2025-07-11尊敬的考生: 您好! 我們誠摯通知您,CDA Level I和 Level II考試大綱將于 2025年7月25日 實(shí)施重大更新。 此次更新旨在確保認(rèn) ...
2025-07-10BI 大數(shù)據(jù)分析師:連接數(shù)據(jù)與業(yè)務(wù)的價值轉(zhuǎn)化者? ? 在大數(shù)據(jù)與商業(yè)智能(Business Intelligence,簡稱 BI)深度融合的時代,BI ...
2025-07-10SQL 在預(yù)測分析中的應(yīng)用:從數(shù)據(jù)查詢到趨勢預(yù)判? ? 在數(shù)據(jù)驅(qū)動決策的時代,預(yù)測分析作為挖掘數(shù)據(jù)潛在價值的核心手段,正被廣泛 ...
2025-07-10數(shù)據(jù)查詢結(jié)束后:分析師的收尾工作與價值深化? ? 在數(shù)據(jù)分析的全流程中,“query end”(查詢結(jié)束)并非工作的終點(diǎn),而是將數(shù) ...
2025-07-10CDA 數(shù)據(jù)分析師考試:從報(bào)考到取證的全攻略? 在數(shù)字經(jīng)濟(jì)蓬勃發(fā)展的今天,數(shù)據(jù)分析師已成為各行業(yè)爭搶的核心人才,而 CDA(Certi ...
2025-07-09【CDA干貨】單樣本趨勢性檢驗(yàn):捕捉數(shù)據(jù)背后的時間軌跡? 在數(shù)據(jù)分析的版圖中,單樣本趨勢性檢驗(yàn)如同一位耐心的偵探,專注于從單 ...
2025-07-09year_month數(shù)據(jù)類型:時間維度的精準(zhǔn)切片? ? 在數(shù)據(jù)的世界里,時間是最不可或缺的維度之一,而year_month數(shù)據(jù)類型就像一把精準(zhǔn) ...
2025-07-09CDA 備考干貨:Python 在數(shù)據(jù)分析中的核心應(yīng)用與實(shí)戰(zhàn)技巧? ? 在 CDA 數(shù)據(jù)分析師認(rèn)證考試中,Python 作為數(shù)據(jù)處理與分析的核心 ...
2025-07-08SPSS 中的 Mann-Kendall 檢驗(yàn):數(shù)據(jù)趨勢與突變分析的有力工具? ? ? 在數(shù)據(jù)分析的廣袤領(lǐng)域中,準(zhǔn)確捕捉數(shù)據(jù)的趨勢變化以及識別 ...
2025-07-08備戰(zhàn) CDA 數(shù)據(jù)分析師考試:需要多久?如何規(guī)劃? CDA(Certified Data Analyst)數(shù)據(jù)分析師認(rèn)證作為國內(nèi)權(quán)威的數(shù)據(jù)分析能力認(rèn)證 ...
2025-07-08LSTM 輸出不確定的成因、影響與應(yīng)對策略? 長短期記憶網(wǎng)絡(luò)(LSTM)作為循環(huán)神經(jīng)網(wǎng)絡(luò)(RNN)的一種變體,憑借獨(dú)特的門控機(jī)制,在 ...
2025-07-07統(tǒng)計(jì)學(xué)方法在市場調(diào)研數(shù)據(jù)中的深度應(yīng)用? 市場調(diào)研是企業(yè)洞察市場動態(tài)、了解消費(fèi)者需求的重要途徑,而統(tǒng)計(jì)學(xué)方法則是市場調(diào)研數(shù) ...
2025-07-07CDA數(shù)據(jù)分析師證書考試全攻略? 在數(shù)字化浪潮席卷全球的當(dāng)下,數(shù)據(jù)已成為企業(yè)決策、行業(yè)發(fā)展的核心驅(qū)動力,數(shù)據(jù)分析師也因此成為 ...
2025-07-07剖析 CDA 數(shù)據(jù)分析師考試題型:解鎖高效備考與答題策略? CDA(Certified Data Analyst)數(shù)據(jù)分析師考試作為衡量數(shù)據(jù)專業(yè)能力的 ...
2025-07-04SQL Server 字符串截取轉(zhuǎn)日期:解鎖數(shù)據(jù)處理的關(guān)鍵技能? 在數(shù)據(jù)處理與分析工作中,數(shù)據(jù)格式的規(guī)范性是保證后續(xù)分析準(zhǔn)確性的基礎(chǔ) ...
2025-07-04CDA 數(shù)據(jù)分析師視角:從數(shù)據(jù)迷霧中探尋商業(yè)真相? 在數(shù)字化浪潮席卷全球的今天,數(shù)據(jù)已成為企業(yè)決策的核心驅(qū)動力,CDA(Certifie ...
2025-07-04CDA 數(shù)據(jù)分析師:開啟數(shù)據(jù)職業(yè)發(fā)展新征程? ? 在數(shù)據(jù)成為核心生產(chǎn)要素的今天,數(shù)據(jù)分析師的職業(yè)價值愈發(fā)凸顯。CDA(Certified D ...
2025-07-03