Sunday, April 8, 2012

A very basic AJAX form validation in Oracle APEX

AJAX can be used efficiently with Oracle APEX to create dynamic form validation on the fly. Here is a simple and clumsy example of how it might be of use.


1. Create your Region and form items. For every form item, we would create a corresponding Display Only item as well to hold validation messages.


2. The Javascript/AJAX code to go in Edit Page >> HTML Header and Body Attributes








Here is the full code that is supposed to go above:


<script language="JavaScript" type="text/javascript">


 function chck()
 { 


var txtItem = $v('P1_NUMBER');

if (txtItem != null && !isNaN(txtItem))
{
var get = new htmldb_Get(null,null,'APPLICATION_PROCESS=VALIDATE',0);
get.add('MSG',txtItem);
gReturn = get.get();

if(gReturn)
{
$x('P1_MSG').innerHTML= gReturn;
}
else
{
$x('P1_MSG').innerHTML='nothing to show';
}
get = null;



else if (isNaN(txtItem))
{
$x('P1_MSG').innerHTML='You must enter a number in text box';
}
else
{
$x('P1_MSG').innerHTML='';
}
}

</script>



3. The code makes a call to an Application Process called VALIDATE which I have created (below) in shared Components. It extracts value from the page item with $v( ) and passes it to the application Item MSG.




4. We now create the application process VALIDATE. This will simply run a query to check if the number entered exists in database and output (via htp.p) the appropriate message.






5.  As you can see above, the process makes use of an item called MSG. This is an application Item we create from Shared Components of the application.


6. Lastly we go to the form Item (P1_NUMBER) which will trigger the process with onBlur event. 





You can test it out here: http://apex.oracle.com/pls/apex/f?p=56259:1

Valid Entries: 0123456789

Saturday, February 4, 2012

SQL Query to Find out Oracle Database Version

To find out your Oracle Database version any of these 2 queries:


SELECT * FROM V$VERSION;


which yields the following result:



BANNER                                                                           
-----------------------------------------------------------------
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production              
PL/SQL Release 11.2.0.2.0 - Production                                           
CORE 11.2.0.2.0 Production                                                         
TNS for 32-bit Windows: Version 11.2.0.2.0 - Production                          
NLSRTL Version 11.2.0.2.0 - Production               





You can also run: 


SELECT * FROM PRODUCT_COMPONENT_VERSION;

Monday, January 23, 2012

Increase JVM Free Memory for Apache Tomcat 6


1) Go to $CATALINA_HOME/bin

2) Create a file setenv.sh (in Linux) or setenv.bat (in Windows)

3) Enter the line:

JAVA_OPTS="-Xms256m -Xmx512m -XX:MaxPermSize=256m"

4) Restart the server

5) Go to your Tomcat manager >> Complete Server Status and verify if the memory has increased or not.

This will increase free memory available and avoid having the Out of Memory error.

Thursday, January 19, 2012

EXP-00091: Exporting questionable statistics.

If you receive this warning message when doing database export, you can turn it off by setting STATISTICS=NONE avoid exporting these statistics during export.



Allowing VNC connection in Oracle Enterprise Linux

If you cant remote connect to your database or to VNC it may be due to firewall restrictions.

1) Start VNC server and check which port its connected on by running: netstat -tlnp
2) Edit the iptables file to allow that port.

$ vim /etc/sysconfig/iptables
3) add this line:
RH-Firewall-1-INPUT -p tcp -m state --state NEW -m tcp --dport xxxx -j ACCEPT
BEFORE
RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited

Replace the xxxx with the port number you found in step 1.

4) Restart your iptables

$ service iptables restart
If you can't connect to database via SQL developer (ie you are getting a network adaptor error) then try this step as well to allow outside connection.


5) Start VNC Server

$ service vncserver restart

Linux: Find out who is listening on ports

 If you suspect the port you are trying to connect to is being blocked, you can check who is listening on that port using netstat -tnlp.

Better to connect as root for a more comprehensive listing. 



bash-3.2$ netstat -tnlp 


tcp     0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      545/sshd       
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      705/cupsd      
tcp6       0      0 :::22                   :::*                    LISTEN      545/sshd       
tcp6       0      0 ::1:631                 :::*                    LISTEN      705/cupsd      




Now you have list of ports that are being used. If you want to find out more about the process that's running on 705, try running:


bash-3.2$ ps -aux | grep 705
 root       705  0.0  0.2   6792  2436 ?        Ss   09:33   0:00 /usr/sbin/cupsd -C /etc/cups/cupsd.conf

Wednesday, January 18, 2012

Creating a Database Link in Oracle

CREATE DATABASE LINK "TESTLINK"
   CONNECT TO "schema_name" IDENTIFIED BY VALUES 'schema_password'
   USING '(DESCRIPTION =
       (ADDRESS_LIST =
         (ADDRESS = (PROTOCOL = TCP)(HOST = 101.102.103.104)(PORT = 1521))
       )
       (CONNECT_DATA =
         (SID = XE)
       )
     )';
 
1) Replace the schema_name, schema_password, Host and port with your setup.
 
2) Login to your schema, and run the query above.
  
Test it by querying "Select * from dual@TESTLINK".