Archive for February 2008

Oracle 10g Express edition

DB legends are releasing their edition as a miniature, previously MS-SQL came with their own mini server. MySQL is always small doing great jobs. and Here I am giving Oracle 10g Express edition. It is cool, very easy to install and get it running. Add to its great things, It offers a cool web interface (see the screenshot below), like Linux admin tools :) . Oracle says it is free to develop, deploy, and distribute. Those who are interested can get their copies at

http://www.oracle.com/technology/products/database/xe/index.html

Oracle web admin screenshot

Producer Consumer – the saviour!

Hi,

I had a task of populating some collections several times,  before uploading them to DB. What happened was, memory had grown rapidly, and atlast the application died with OutOfMemoryError :(

That time my lead was suggesting to go to this pattern, Producer-Consumer!  Like, one guy will be populating the collection, In parallel another guy will be reading from the collection and update the db! Wonderful man, this design is highly scalable, if you implement correctly! For more info, see the simple example here, http://www.java2s.com/Code/Java/Threads/ProducerconsumerforJ2SE15usingconcurrent.htm

java.util.zip.ZipException: invalid CEN header (encrypted entry)

friends,This week started with some more problems :) . Nothing to worry, problems only feed us! Otherwise, who will give us job!!! Today I was trying to unzip a zip file and read the contents inside the file, using java.util.zip.ZipFile. It was working fine till I increased the file size. The zip file is around 160MB, and the single file inside that zip file is 4.5GB contains raw text. I hit with the exception

java.util.zip.ZipException: invalid CEN header (encrypted entry)

Pathetic, I was totally helpless! Later I came to know that It is a open bug in java, which will not support above 3.2G!  I am in darkness. Latermy lead had pointed out that is due to java’s non-compliance to zip64, which is fixed in jdk1.6, 24th build. I need to get it installed and get rid of this issue!

auto increment in oracle

This post is regarding auto increment in oracle. Usually I used to add AUTO_INCREMENT flag in mysql. But it is not a single word task oracle. we need to create sequence and trigger to do the same. please see the following examples 1. Here is my table structure.

CREATE TABLE FEED_DETAIL
(
FEED_ID NUMBER(6, 0),
FEED_TEXT VARCHAR2(128 BYTE),
FEED_TITLE VARCHAR2(128 BYTE),
FEED_TYPE VARCHAR2(12 BYTE),
XML_URL VARCHAR2(128 BYTE),
HTML_URL VARCHAR2(128 BYTE)
)
2. lets play with FEED_ID now. lets make it auto increment. create a sequence now

create sequence FEED_DETAIL_SEQUENCE
start with 1
increment by 1
nomaxvalue;

A sequence is an object in Oracle that is used to generate a number sequence. This can be useful when you need to create a unique number to act as a primary key.

3. Now create a trigger. A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database. Triggers can restrict access to specific data, perform logging, or audit data modifications.

create or replace trigger FEED_DETAIL_TRIGGER
before insert on FEED_DETAIL
for each row
begin
select FEED_DETAIL_SEQUENCE.nextval into :new.feed_id from dual;
end;

Now insert the values

insert into feed_detail (feed_text, feed_title, feed_type, xml_url, html_url) values('a', 'b', 'c', 'd', 'e');
insert into feed_detail (feed_text, feed_title, feed_type, xml_url, html_url) values('a', 'b', 'c', 'd', 'e');

Enjoy auto incrementing column now!

java.sql.SQLException: ORA-01000: maximum open cursors exceeded

As I have told you in my previous post, I was trying to read from a table within a loop. I am opening a new connection, new statement and firing the query to get the resultset. It was working fine for a few records, finally it dies with this exception

java.sql.SQLException: ORA-01000: maximum open cursors exceeded

Alas, I forgot to close the resultset!!