XP-rience

Something that I'd like to share with you!

Saturday, October 31, 2009

Quick Start - Install and Run Apache Tomcat

No comments :
Obtain a copy of Apache Tomcat <version> from tomcat.apache.org.
Download >> Binary Distributions >> Core >> zip



Obtain a copy of JDK from Java SE Downloads. There any many options there. Just pick;
Java SE Development Kit (JDK) >> JDK <version> Update <update>

Install the JDK. Please refer to Java SE Downloads page for complete/detail installation instruction.

Unzip Apache Tomcat to a new directory.


Set environment variable JAVA_HOME pointing to the JDK directory.
JAVA_HOME = C:\Program Files\Java\jdk<version>






Locate D:\apache-tomcat-<version>\bin\ and double click startup.bat to start the Apache Tomcat web server.



A command prompt window will popup showing the status.



To confirm it is really running, point your browser to http://localhost:8080. (Default Apache Tomcat port = 8080)



To shutdown Apache Tomcat, simply double click shutdown.bat from the same location that is D:\apache-tomcat-<version>\bin\

Sunday, October 18, 2009

Toad 9.7 & Oracle Instant Client 11.1

10 comments :
Referring to Toad + Oracle instant client, I tried to set it up but unfortunately it doesn't work out for me. Some extra additional steps help to resolve the issue and I love to share it here.

First, download Oracle Client from Oracle Database Instant Client. Instant Client Package - Basic Lite wil do just fine. (about 17MB)

Next, create 4 folders ( recommended under c:\Program Files ) according to folder hierarchy below;



You should have 4 folders.

C:\Program Files\oracle
C:\Program Files\oracle\bin
C:\Program Files\oracle\network
C:\Program Files\oracle\network\admin


Now, extract the Instant Client Package to C:\Program Files\oracle\bin ( make sure the oci.dll is in the C:\Program Files\oracle\bin )



Right click at My Computer > Properties > Goto Advance tab > Click Environment Variables. Add listed Environment Variables below to your OS.

LD_LIBRARY_PATH = C:\Program Files\oracle\bin
ORACLE_HOME = C:\Program Files\oracle
ORACLE_HOME_NAME = C:\Program Files\oracle
SQL_PATH = C:\Program Files\oracle
TNS_ADMIN = C:\Program Files\oracle\network\admin




Under system variables, edit Path, add C:\Program Files\oracle\bin to the end of other path (don't forget to separate it with ";")



Copy/create 3 simple *.ora files below to C:\Program Files\oracle\network\admin



tnsnames.ora
DEV =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = foo)(PORT = 1531))
)
(CONNECT_DATA =
(SERVICE_NAME = foo)
)
)



sqlnet.ora
NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, HOSTNAME)
NAMES.DEFAULT_DOMAIN = WORLD
TRACE_LEVEL_CLIENT = OFF
SQLNET.EXPIRE_TIME = 30


ldap.ora
DEFAULT_ADMIN_CONTEXT = “ou=oracledatabases,dc=mycompany,dc=com”
DIRECTORY_SERVERS = (ldap_server.mycompany.com:389:636)
DIRECTORY_SERVER_TYPE = OID


Finally, test it out.



The drop down button seems to be highlighted in red but it works. I've tried it with several DB connections.

Thursday, October 15, 2009

Setting up a simple Java stored procedure/function in Oracle

No comments :
Starting with Oracle 8i, we can write Java Stored Procedures/Functions within the database. Stored procedures/functions are Java methods published to SQL and stored in the database for general usage. It also could be called by a trigger. Example; to send an email whenever a specific row has been inserted into the table.

Run the $ORACLE_HOME/javavm/install/initjvm.sql script from SYS AS SYSDBA to install the Oracle JServer Option on a database.

oracle@myserver:~> sqlplus '/ as sysdba' @$ORACLE_HOME/javavm/install/initjvm.sql


(This process is reversible. It could be done by running the rmjvm.sql script to uninstall the Oracle JServer Option from the database)

Grant JAVAUSERPRIV to selected user.

oracle@myserver:~> sqlplus '/ as sysdba'
SQL> GRANT JAVAUSERPRIV TO theuser;

Grant succeeded.


You could use a console but I'm using Toad by Quest Software for the next step. Create Java source from TOAD by login to the Oracle using the Java granted user.



CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "Hello" AS
public class hello{
public static String world() {
return "hello world ";
}
};
/


Now verify the created Java method from the Java tab under schema browser.



Next, create a procedure/function to call the Java method. Remember, function should return one value but procedure don't.



CREATE OR REPLACE function Hello RETURN VARCHAR2
as LANGUAGE JAVA NAME 'hello.world() return String';
/


Finally, test it out with a simple SELECT FROM DUAL SQL.