Thursday, November 21, 2013

Simple Step to Execute Java Programe from Oracle

Step 1
Write java prg and compile from Oracle bin folder
public class Hello
{
  public static String world()
  {
    return "Hello world";
  }
}
D:\app\oracle\product\11.1.0\db_1\BIN>javac  -target 1.5 Hello.java
------------------------------------------------------------------------
Step 2
load the class file
D:\app\oracle\product\11.1.0\db_1\BIN>loadjava -user hr/hr Hello.class
-------------------------------------------------------------------------
Step 3
Write a plsql function in SQL
CREATE OR REPLACE FUNCTION helloworld RETURN VARCHAR2 AS
LANGUAGE JAVA NAME 'Hello.world () return java.lang.String';
/
------------------------------------------------------------------------
Step 4
select helloworld() from dual;
Hello world

Oracle 11g Virtual Columns

VIRTUAL COLUMNS

   With 11g release, Oracle allows user to explicitly create virtual columns in a table.  These virtual columns are associated with an expression, which always generate the value for the virtual column.
 

  •       The data type of the virtual column is also optional. If it is not explicitly specified, it attains the return data type of the expression.
  •         The virtual property of a column can be queried in VIRTUAL_COLUMN of USER_TAB_COLS table.
  •          INSERT and UPDATE operation are disallowed on virtual columns.

EXAMPLE :

SQL> create table orders(oid number,oname varchar2(12),qty as (oid*30));

SQL> insert into orders(oid,oname) values(1,'Mouse');

SQL> insert into orders(oid,oname) values(2,'Keyboard');

SQL> commit;

SQL> select * from orders;

SQL> select * from USER_TAB_COLS where TABLE_NAME='ORDERS'

SQL> desc orders;

Tuesday, January 15, 2008

Steps required to implement a Java Database Program

STEP 1: Loading Drivers
Class.ForName("sun.jdbc.odbc.JdbcOdbcDriver")

STEP 2: Making the Connection
Connection conn = DriverManager.getConnection("jdbc:odbc:");

STEP 3: Creating JDBC Statements
Statement stmt = conn.createStatement();

STEP 4: Executing the Statement
ResultSet rs = stmt.executeQuery("select * from student");

STEP 5: Looping through the ResultSet
System.out.println(rs.getInt("ID"));

STEP 6: Closing the Connection and Statement Objects
conn.close()
stmt.close()

Thanks & Regards
Nidhika