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

推荐订阅源

GbyAI
GbyAI
J
Java Code Geeks
雷峰网
雷峰网
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
V
Vulnerabilities – Threatpost
S
Securelist
The Hacker News
The Hacker News
The Register - Security
The Register - Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Help Net Security
Help Net Security
G
Google Developers Blog
Hugging Face - Blog
Hugging Face - Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
M
MIT News - Artificial intelligence
AI
AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The GitHub Blog
The GitHub Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Schneier on Security
Schneier on Security
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
H
Hacker News: Front Page
博客园 - 司徒正美
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Security Latest
Security Latest
Engineering at Meta
Engineering at Meta
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
U
Unit 42
V
V2EX
V2EX - 技术
V2EX - 技术
L
LINUX DO - 最新话题
aimingoo的专栏
aimingoo的专栏
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
P
Privacy & Cybersecurity Law Blog
美团技术团队
小众软件
小众软件
F
Fortinet All Blogs

博客园 - 飞翔

杂记 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