知识大全 JDBC存取Oralce数据库的注意几点事项
Posted 数据库
篇首语:她其实只是想要个拥抱,可你却总是在讲道理。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 JDBC存取Oralce数据库的注意几点事项相关的知识,希望对你有一定的参考价值。
JDBC存取Oralce数据库的注意几点事项 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
Be careful with date type column Just like Y K 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 Jan st Insert into test (user_name user_birthday sex) values( Bob to_date( YYMMDD M ); Ok now let s check Bob s birthday: Select to_char(birthday YYYYMMDD ) as birthday from test where user_name= Bob ; Birthday Ok its st century now don t fet it How to operate on Clob: Clob type is to save single byte character data up to 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( 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(); mit(); 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[ ]; //set to K; int readLen = asciiStream read(tempBody ); String tempString = (new String(tempBody)) substring( readLen); Be careful with PreparedStatement When you use PreparedStatement to pre pile and execute SQL String you must close it after transaction ending Otherwise you ll got an exception named ORA : 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 exception So only prepare statement once for particular sql strings set Use set XXX(int index XXX value) method to set column values cha138/Article/program/Oracle/201311/17137相关参考
Hibernate是对JDBC的轻量级封装因此在很多情况下Hibernate的性能比直接使用JDBC存取数据库要低然而通过正确的方法和策略在使用Hibernate的时候还是可以非常接近直接使用JD
研究了好几天终于有了一个比较完整查看oracle的数据日志方法oracle没有想sqlserver那样有sqlE工具来辅助查询只能利用oracle自己的工具 一如何分析即LogMiner解释
通过JDBC连接oracle数据库 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!Java数据库连接
Spring通过JDBC配置数据库 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!XXXdataxm
常用数据库JDBC连接写法大全 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! MySQL()mm
通过JDBC连接oracle数据库的技巧 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! Java
JDBC数据库驱动程序种类及选择 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 现在目前数据库驱
常用数据库JDBC连接写法全攻略 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 常用数据库JDB
加快JDBC中JSP数据库的访问速度 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! JSP程序都
在JDBC设计中加速JSP访问数据库 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! JSP程序都