---
title: "Oracle10g 操作大对象"
author: "ztfjava"
date: "2010-09-13T20:16:28Z"
tags: []
categories: ["编程语言"]
slug: "oracle10g"
draft: false
lastmod: "2010-09-13T20:16:28Z"
id: 762403
url: "https://ztfjava.iteye.com/blog/762403"
---

package com.ztf.getResult;




import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

import java.sql.Statement;




import oracle.jdbc.driver.OraclePreparedStatement;




import com.ztf.getImp.IgetResult;

import com.ztf.util.GetConnection;




public class getRestult implements IgetResult {




	public void getEmpEname(){

		

		Connection conn = null;

		String sql="select ename from emp";

		Statement st =null;

		ResultSet rs =null;

		conn = GetConnection.getConnection();

		try {

			st = conn.createStatement();

			rs = st.executeQuery(sql);

			while(rs.next()){

				System.out.println(rs.getString("ename"));

			}

		} catch (SQLException e) {

			e.printStackTrace();

		}

		finally{

			try {

				rs.close();

				st.close();

				conn.close();

			} catch (SQLException e) {

				e.printStackTrace();

			}

		}

	}




	/*

	* 用Statement进行测试 最大插入的字符为为4000 字符

	*/

	

	/*

	

	public void InsertClob() {

		

		Connection conn = null;

		Statement st = null;

		String sql ="INSERT INTO T VALUES(2,'"+getStr(4001,"a")+"')";

		try {

			conn = GetConnection.getConnection();

			st = conn.createStatement();

			st.executeQuery(sql);

			conn.commit();

			System.out.println("插入成功");

		} catch (SQLException e) {

			e.printStackTrace();

		}	

	}

	

	*/

	

	/*

	* 用PraperStatement测试能插入的最大的长度；

	* 为：

	*/

	

/*

	public void InsertClob() {

		

		Connection conn = null;

		PreparedStatement ps = null;

		String sql ="INSERT INTO T VALUES(10,?)";

		conn = GetConnection.getConnection();

		try {

			ps= conn.prepareStatement(sql);

			ps.setString(1, getStr(60000,"s"));

			ps.executeUpdate();

			conn.commit();

			System.out.println(" 插入成功");

		} catch (SQLException e) {

			e.printStackTrace();

		}

		finally{

			try {

				conn.close();

				ps.close();

			} catch (SQLException e) {

				e.printStackTrace();

			}

			

		}

		

	}

	*/

	

	/*

	*要想插入数据不受限制 可以用Oracle提供的方法来插入数据

	*OraclePrapredStatement

	*/

	

	public void InsertClob() {

		Connection conn = null;

		String sql="INSERT INTO T VALUES(10,?)";

		OraclePreparedStatement rps;

		try {

			conn = GetConnection.getConnection() ;

			rps = (OraclePreparedStatement) conn.prepareStatement(sql);

			rps.setString(1, getStr(1000000,"X"));

			rps.executeQuery();

			conn.commit();

		} catch (Exception e) {

			e.printStackTrace();

		}

	}




	

	private String getStr(int x,String str){

		String strx="";

		for(int i=0 ;i<x;i++){

			strx +=str;

		}

		return strx;

	}

}