|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
j2EE和asp比较,其实也没什么比的,原因和我上面说那些比较差不了多少,也是稳定性,安全性,J2EE比asp高,速度上比不过asp,asp也是延续着它的拖拽控件的方法,提高速度。
展现JDBC存取ORACLE年夜型数据对象LOB几种情形的树模类
importjava.io.*;
importjava.util.*;
importjava.sql.*;
publicclassLobPros
{
/**
*ORACLE驱动程序
*/
privatestaticfinalStringDRIVER="oracle.jdbc.driver.OracleDriver";
/**
*ORACLE毗连用URL
*/
privatestaticfinalStringURL="jdbc:oracle:thin:@test2000:1521:orac";
/**
*用户名
*/
privatestaticfinalStringUSER="user";
/**
*暗码
*/
privatestaticfinalStringPASSWORD="pswd";
/**
*数据库毗连
*/
privatestaticConnectionconn=null;
/**
*SQL语句对象
*/
privatestaticStatementstmt=null;
/**
*@roseuid3EDA089E02BC
*/
publicLobPros()
{
}
/**
*往数据库中拔出一个新的CLOB对象
*
*@paraminfile-数据文件
*@throwsjava.lang.Exception
*@roseuid3EDA04A902BC
*/
publicstaticvoidclobInsert(Stringinfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*拔出一个空的CLOB对象*/
stmt.executeUpdate("INSERTINTOTEST_CLOBVALUES(111,EMPTY_CLOB())");
/*查询此CLOB对象并锁定*/
ResultSetrs=stmt.executeQuery("SELECTCLOBCOLFROMTEST_CLOBWHEREID=111FORUPDATE");
while(rs.next()){
/*掏出此CLOB对象*/
oracle.sql.CLOBclob=(oracle.sql.CLOB)rs.getClob("CLOBCOL");
/*向CLOB对象中写进数据*/
BufferedWriterout=newBufferedWriter(clob.getCharacterOutputStream());
BufferedReaderin=newBufferedReader(newFileReader(infile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*修正CLOB对象(是在原CLOB对象基本长进行掩盖式的修正)
*
*@paraminfile-数据文件
*@throwsjava.lang.Exception
*@roseuid3EDA04B60367
*/
publicstaticvoidclobModify(Stringinfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*查询CLOB对象并锁定*/
ResultSetrs=stmt.executeQuery("SELECTCLOBCOLFROMTEST_CLOBWHEREID=111FORUPDATE");
while(rs.next()){
/*猎取此CLOB对象*/
oracle.sql.CLOBclob=(oracle.sql.CLOB)rs.getClob("CLOBCOL");
/*举行掩盖式修正*/
BufferedWriterout=newBufferedWriter(clob.getCharacterOutputStream());
BufferedReaderin=newBufferedReader(newFileReader(infile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*交换CLOB对象(将原CLOB对象扫除,换成一个全新的CLOB对象)
*
*@paraminfile-数据文件
*@throwsjava.lang.Exception
*@roseuid3EDA04BF01E1
*/
publicstaticvoidclobReplace(Stringinfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*清空原CLOB对象*/
stmt.executeUpdate("UPDATETEST_CLOBSETCLOBCOL=EMPTY_CLOB()WHEREID=111");
/*查询CLOB对象并锁定*/
ResultSetrs=stmt.executeQuery("SELECTCLOBCOLFROMTEST_CLOBWHEREID=111FORUPDATE");
while(rs.next()){
/*猎取此CLOB对象*/
oracle.sql.CLOBclob=(oracle.sql.CLOB)rs.getClob("CLOBCOL");
/*更新数据*/
BufferedWriterout=newBufferedWriter(clob.getCharacterOutputStream());
BufferedReaderin=newBufferedReader(newFileReader(infile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*CLOB对象读取
*
*@paramoutfile-输入文件名
*@throwsjava.lang.Exception
*@roseuid3EDA04D80116
*/
publicstaticvoidclobRead(Stringoutfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*查询CLOB对象*/
ResultSetrs=stmt.executeQuery("SELECT*FROMTEST_CLOBWHEREID=111");
while(rs.next()){
/*猎取CLOB对象*/
oracle.sql.CLOBclob=(oracle.sql.CLOB)rs.getClob("CLOBCOL");
/*以字符情势输入*/
BufferedReaderin=newBufferedReader(clob.getCharacterStream());
BufferedWriterout=newBufferedWriter(newFileWriter(outfile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
out.close();
in.close();
}
}catch(Exceptionex){
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*向数据库中拔出一个新的BLOB对象
*
*@paraminfile-数据文件
*@throwsjava.lang.Exception
*@roseuid3EDA04E300F6
*/
publicstaticvoidblobInsert(Stringinfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*拔出一个空的BLOB对象*/
stmt.executeUpdate("INSERTINTOTEST_BLOBVALUES(222,EMPTY_BLOB())");
/*查询此BLOB对象并锁定*/
ResultSetrs=stmt.executeQuery("SELECTBLOBCOLFROMTEST_BLOBWHEREID=222FORUPDATE");
while(rs.next()){
/*掏出此BLOB对象*/
oracle.sql.BLOBblob=(oracle.sql.BLOB)rs.getBlob("BLOBCOL");
/*向BLOB对象中写进数据*/
BufferedOutputStreamout=newBufferedOutputStream(blob.getBinaryOutputStream());
BufferedInputStreamin=newBufferedInputStream(newFileInputStream(infile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*修正BLOB对象(是在原BLOB对象基本长进行掩盖式的修正)
*
*@paraminfile-数据文件
*@throwsjava.lang.Exception
*@roseuid3EDA04E90106
*/
publicstaticvoidblobModify(Stringinfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*查询BLOB对象并锁定*/
ResultSetrs=stmt.executeQuery("SELECTBLOBCOLFROMTEST_BLOBWHEREID=222FORUPDATE");
while(rs.next()){
/*掏出此BLOB对象*/
oracle.sql.BLOBblob=(oracle.sql.BLOB)rs.getBlob("BLOBCOL");
/*向BLOB对象中写进数据*/
BufferedOutputStreamout=newBufferedOutputStream(blob.getBinaryOutputStream());
BufferedInputStreamin=newBufferedInputStream(newFileInputStream(infile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*交换BLOB对象(将原BLOB对象扫除,换成一个全新的BLOB对象)
*
*@paraminfile-数据文件
*@throwsjava.lang.Exception
*@roseuid3EDA0505000C
*/
publicstaticvoidblobReplace(Stringinfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*清空原BLOB对象*/
stmt.executeUpdate("UPDATETEST_BLOBSETBLOBCOL=EMPTY_BLOB()WHEREID=222");
/*查询此BLOB对象并锁定*/
ResultSetrs=stmt.executeQuery("SELECTBLOBCOLFROMTEST_BLOBWHEREID=222FORUPDATE");
while(rs.next()){
/*掏出此BLOB对象*/
oracle.sql.BLOBblob=(oracle.sql.BLOB)rs.getBlob("BLOBCOL");
/*向BLOB对象中写进数据*/
BufferedOutputStreamout=newBufferedOutputStream(blob.getBinaryOutputStream());
BufferedInputStreamin=newBufferedInputStream(newFileInputStream(infile));
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*BLOB对象读取
*
*@paramoutfile-输入文件名
*@throwsjava.lang.Exception
*@roseuid3EDA050B003B
*/
publicstaticvoidblobRead(Stringoutfile)throwsException
{
/*设定不主动提交*/
booleandefaultCommit=conn.getAutoCommit();
conn.setAutoCommit(false);
try{
/*查询BLOB对象*/
ResultSetrs=stmt.executeQuery("SELECTBLOBCOLFROMTEST_BLOBWHEREID=222");
while(rs.next()){
/*掏出此BLOB对象*/
oracle.sql.BLOBblob=(oracle.sql.BLOB)rs.getBlob("BLOBCOL");
/*以二进制情势输入*/
BufferedOutputStreamout=newBufferedOutputStream(newFileOutputStream(outfile));
BufferedInputStreamin=newBufferedInputStream(blob.getBinaryStream());
intc;
while((c=in.read())!=-1){
out.write(c);
}
in.close();
out.close();
}
/*正式提交*/
conn.commit();
}catch(Exceptionex){
/*堕落回滚*/
conn.rollback();
throwex;
}
/*恢回复提交形态*/
conn.setAutoCommit(defaultCommit);
}
/**
*创建测试用表格
*@throwsException
*/
publicstaticvoidcreateTables()throwsException{
try{
stmt.executeUpdate("CREATETABLETEST_CLOB(IDNUMBER(3),CLOBCOLCLOB)");
stmt.executeUpdate("CREATETABLETEST_BLOB(IDNUMBER(3),BLOBCOLBLOB)");
}catch(Exceptionex){
}
}
/**
*@paramargs-命令行参数
*@throwsjava.lang.Exception
*@roseuid3EDA052002AC
*/
publicstaticvoidmain(String[]args)throwsException
{
/*装载驱动,创建数据库毗连*/
Class.forName(DRIVER);
conn=DriverManager.getConnection(URL,USER,PASSWORD);
stmt=conn.createStatement();
/*创建测试表格*/
createTables();
/*CLOB对象拔出测试*/
clobInsert("c:/clobInsert.txt");
clobRead("c:/clobInsert.out");
/*CLOB对象修正测试*/
clobModify("c:/clobModify.txt");
clobRead("c:/clobModify.out");
/*CLOB对象交换测试*/
clobReplace("c:/clobReplace.txt");
clobRead("c:/clobReplace.out");
/*BLOB对象拔出测试*/
blobInsert("c:/blobInsert.doc");
blobRead("c:/blobInsert.out");
/*BLOB对象修正测试*/
blobModify("c:/blobModify.doc");
blobRead("c:/blobModify.out");
/*BLOB对象交换测试*/
blobReplace("c:/blobReplace.doc");
blobRead("c:/bolbReplace.out");
/*封闭资本加入*/
conn.close();
System.exit(0);
}
}
没有那个大公司会傻了吧唧用.net开发大型项目,开发了,那等于自己一半的生命线被微软握着呢。而.net不行,限制在window系统,又是捆绑,鄙视微软之! |
|