oracle的varchar2(4000)可以儲存2000個漢字或者4000個英文字元? .

來源:互聯網
上載者:User
  一般情況下用ps.setString()的辦法是不行的, 因為oracle的驅動會把一個中文字用三個位元組表示,加上jdbc本身對字元的的限制為2000, 也就是600多字,如果是英文字元也只能到2000,英文用2個位元組表示, 但是oci驅動沒有這個限制,如何能通過jdbc把2000個漢字插進去呢? 利用PreparedStatement的setCharacterStream方法就可以了, Reader  reader = new StringReader(你需要插入的長字元); ps.setCharacterStream(1,reader,字元長度); 這個就可以把2000個中文字元插入到表中 如果在hibernate中怎麼辦呢?暫時沒有想到!換成clob類型嗎?好像問題還不少!     Reader  reader = new StringReader(new String(chars));   PreparedStatement ps = conn.prepareStatement("insert into tvar (value) values (?)");
  ps.setCharacterStream(1,reader,chars.length);
 ps.executeUpdate();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.