网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
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,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.ERP performance tuning 第六天.
.实例讲解Ora-12514和Ora-12514解.
.如何才能使用查询改写提高查询性.
.Oracle数据库中fast刷新会受到哪.
.轻松取得Oracle 9i建表和索引DDL.
.Oracle 9i 数据库设计指引全集(.
.如何有效地利用oracle的数据字典.
.实例讲解如何通过Oracle成功发送.
.Oracle数据库技术(28).
.提纲挈领Oracle数据库灾难防护技.
.讲解Oracle数据库的全文索引设置.
.Oracle 9i轻松取得建表和索引的D.
.Oracle处理多媒体信息的原理及展.
.以 spfdisk 分割硬盘的一个范例.
.24×7环境转移ORACLE数据库.
.使用XMLTransform和XSL-FO格式化.
.undo表空间暴长后如何才能取消自.
.如何处理Oracle中的坏块问题.
.rman备份,控制文件丢失的解决办法.
.TestKing Oracle 1z0-023 V5.

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

发表日期: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进程内存占用问题解决方法 人气:1038
下一篇:在Oracle数据库中连接异种数据源 人气:584
浏览全部Oracle教程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐