动态网站制作指南
[  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库学院 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Access教程,DB2教程,数据库安全,数据库文摘
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Oracle教程 ]的信息

本月文章推荐
.oracle中实现主键的自动增加.
.Oracle 数据库安全策略的具体分析.
.用SQL进行函数查询.
.Oracle中应用Export的一个问题.
.如何一次处理一整个目录.
.oracle9.i数据库.
.Oracle 9i Data Guard进行数据库.
.linux下安装oracle9i.
.RedHat 日志文件.
.用JDBC连接Oracle数据库的十项技.
.浅谈Oracle数据库的建模与设计.
.Oracle安全全接触(完整版)一.
.关于对bfile的基本操作全面介绍.
.Oracle裸设备(raw device)问答.
.Oracle DBA 日常管理.
.Oracle安装(linux)总结一下.
.在全文索引建立的目录不存在情况.
.Oracle数据库连接.
.Oracle下的数据分片技术.
.ORACLE 面试问题-技术篇(1).

JDBC存取Oralce数据库的注意几点事项

文章类别:Oracle教程 | 发表日期:2008-2-9 |


Be careful with date type column.
  
  Just like Y2K, when you try to give a value to a column which type is date, you should determine the year area with YYYY not YY.
  
  Suppose there is a user, Named Bob, Male, borned on 1977,Jan, 1st.
  
  Insert into test (user_name, user_birthday, sex) values(‘Bob’, to_date(‘770109’,’YYMMDD’,’M’);
  
  Ok, now let’s check Bob’s birthday:
  
  Select to_char(birthday,’YYYYMMDD’) as birthday from test where user_name=’Bob’;
  
  Birthday
  
  20770109
  
  Ok, its 21st century now, don’t forget it.
  
  How to operate on Clob:
  
  Clob type is to save single-byte character data up to 4 gigabytes.
  
  If you are a newer to use clob, you must find it’s not so easy to operate on it! Ok, take it easy, from now on I’ll give an example to insert, update, retrieve clob type values from test.
  
  → Insert new value for clob type column:
  
  Because it is now allowed to insert string directly into Clob type column, we must insert an Empty_clob into the table.
  
  Suppose we have established a connection to database, and the reference of the Connection object it conn.
  
  String sql = “insert into test (user_name, user_birthday, sex, biography) values(‘Bob’, to_date(‘19770109’,’yyyymmdd’), ‘M’,EMPTY_CLOB())”;
  
  PreparedStatement stmt = conn.prepareStatement(sql);
  
  Stmt.execute();
  
  Now an Empty_Clob object has be signed to biography.
  
  To give real value of biography column, use the following code fragment:
  
  sql = “select biography from test where user_name=’Bob’ for update”;
  
  stmt = conn.prepareStatement(sql);
  
  ResultSet rs = stmt.executeQuery();
  
  Please remembered the “for update” clause, it’s very important. This particular clause means you told the database to prepare the biography of Bob for update.
  
  Oracle.sql.CLOB clob = (oracle.sql.CLOB)((oracle.jdbc.OracleResultSet)rs).getCLOB("biography");
  
  Java.io.OutputStream clobWriter = clob.getAsciiOutputStream();
  
  byte[] temp = currentBiography.getBytes();
  
  (supposed currentBiography is the value to be update to database)
  
  clobWriter.write(temp);
  
  clobWriter.flush();
  
  clobWriter.close();
  
  rs.close();
  
  stmt.close();
  
  conn.commit();
  
  
  Ok, the biography has been updated.
  
  → When you retrieve clob from database, remember to use InputStream.
  
  oracle.sql.CLOB clob = (oracle.sql.CLOB)rs.getClob("biography");
  
  java.io.InputStream asciiStream = clob.getAsciiStream();
  
  byte[] tempBody = new byte[1024]; //set to 1K;
  
  int readLen = asciiStream.read(tempBody,0,1024);
  
  String tempString = (new String(tempBody)).substring(0,readLen);
  
  Be careful with PreparedStatement
  When you use PreparedStatement to pre-compile and execute SQL String, you must close it after transaction ending. Otherwise you’ll got an exception named ORA 0001: maximum cursors exceeded!
  
  I’m not sure about cursor, there is a parameter in the init.ora file which will used by oracle database. In this file, max cursors is defined.
  
  Actually when try to prepare statement and execute in a loop block. You may also cause ORA 0001 exception.
  
  So only prepare statement once for particular sql strings set. Use set XXX(int index, XXX value) method to set column values.



上一篇:Oracle9i进程内存占用问题解决方法 人气:361
下一篇:在Oracle数据库中连接异种数据源 人气:225
点击此处浏览全部Oracle教程的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-5-16 乘风多用户PHP统计系统 v3.4
2008-5-16 轩溪下载系统 v3.78 build 0515
2008-5-16 普沙B2B 浙江省商贸网 v2.0
2008-5-16 asp抓蜘蛛的小程序 v1.0
2008-5-16 齐齐乐网私服发布站 仿haosf新版
2008-5-16 IssTech信息反馈系统 v1.0
2008-5-16 自由领域大头贴(js接口版) 修正版
2008-5-16 医院网站系统
2008-5-16 智拓-分类信息管理系统 v5.0
2008-5-7 Windows XP SP3 官方英文版
2008-5-7 Windows XP SP3 官方香港中文版
2008-5-7 Windows XP SP3 官方繁体中文版
2008-5-7 Windows XP SP3 官方简体中文版
2008-4-30 Multiple Unzip Wizard 1.02
2008-4-30 Multiple Unrar Wizard 1.0.0
2008-4-30 WinZip Install/Try/Uninstall a
2008-4-30 ZIP压缩文件修复器WzipFix 2.0
2008-4-30 Pentazip 6.01 Build 189 For Wi
  发表评论
姓 名: 验证码: [ 全部贴吧 ] [ 浏览评论 ]
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報