惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
Spread Privacy
Spread Privacy
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
SecWiki News
SecWiki News
腾讯CDC
P
Privacy International News Feed
Webroot Blog
Webroot Blog
J
Java Code Geeks
爱范儿
爱范儿
A
About on SuperTechFans
S
Secure Thoughts
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
D
DataBreaches.Net
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Security Latest
Security Latest
Forbes - Security
Forbes - Security
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threatpost
量子位
MongoDB | Blog
MongoDB | Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Vercel News
Vercel News
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
GbyAI
GbyAI
S
Security @ Cisco Blogs
T
The Exploit Database - CXSecurity.com
Help Net Security
Help Net Security
V
Visual Studio Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 聂微东
P
Proofpoint News Feed
C
CERT Recently Published Vulnerability Notes
Attack and Defense Labs
Attack and Defense Labs

博客园 - 飞翔

杂记 VI使用技巧 浮躁,太浮躁了 有空看看的一些技术文章 工作流概述 JavaMail 应用 - 飞翔 - 博客园 权限系统概要 --转 看的的有意思的帖子收集 动态编译JAVA程序 Log4j基本使用方法 dom4j 读取xml文件时遇到的怪问题(org.dom4j.DocumentException: no protocol) spring+hibernate 处理oracle clob (编辑中) 多线程 Thread 学习杂记 Struts menu的使用(动态数据) 网页 的一些信息 - 飞翔 - 博客园 Struts Validator验证器使用指南 错误汇总 谈IFRAME标签的使用 appfuse 杂记 - 飞翔 - 博客园
Oracle插入大量文字
飞翔 · 2005-09-22 · via 博客园 - 飞翔

 使用PreparedStatement的setString(i, s)时出现:

可以参考帖子:http://community.csdn.net/Expert/topic/3936/3936672.xml?temp=.2879145

 java.sql.SQLException: 数据大小超出此类型的最大值: 3000

后面那个值大小不定,  感觉与s大小有关

表结构

create table test(

name char(32),

addr   varchar(3000)                       //varchar2也一样

)

解决办法: 采用setCharacterStream


import java.sql.*;
import java.io.*;
import java.util.*;

/**
 * oracle测试
 * @author kingfish
 * @version 1.0
 */
public class TestOra {
  public static void testORACLE() {
    String url = "jdbc:oracle:thin:@localhost:1521:oradb";
    String username = "system";
    String password = "manager";

    Connection conn = null;
    try {
      Class.forName("oracle.jdbc.driver.OracleDriver");
      conn = DriverManager.getConnection(url, username, password);
    }
    catch (Exception e) {
      e.printStackTrace();
      return;
    }

    char[] carray = new char[1000];
    Arrays.fill(carray, '我');
    String s = new String(carray);
    try {
      PreparedStatement pst = conn.prepareStatement(
          "insert into test(name,addr) values(?,?)");
      pst.setString(1, "kingfish");

      pst.setCharacterStream(2,
                             new InputStreamReader(new ByteArrayInputStream(s.
          getBytes())), s.length());

      //pst.setString(2,s);  //用此句则异常
      pst.execute();

      Statement st = conn.createStatement();
      ResultSet r = st.executeQuery("SELECT * from test");

      while (r.next()) {
        s = r.getString(2);
        System.out.println("len=" + s.length());
        System.out.println("value=" + s);
      }

      r.close();
      st.close();
      conn.close();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * 测试
   * @param args String[]
   */
  public static void main(String[] args) {
    testORACLE();
  }
}


说明: 引起此问题的原因估计和OraclePreparedStatement中的setString的实现有关.

kingfish

2005.4.14

本文引用通告地址: http://blog.csdn.net/kingfish/services/trackbacks/348062.aspx