How to use datasource from weblogic/ How to access datasource from weblogic/ Type 3 connectivity

This program demonstrate , how to connect a java program to database using middle ware. this connectivity is known as type 3 connectivity and can be done using middle ware server  that provides the facilities to create datasource.
 Here , I am using weblogic 10.3 to create datasource and accessing MySql through core java application. This application will connect to abc data source created on weblogic and get Connection from datasource.
then do whatever we does on type 1 connectivity.
To run this program, you have to put weblogic.jar file into class-path otherwise it will create run-time problem.
Example :

import javax.sql.*;

import java.sql.*;

import java.util.*;

import javax.naming.*;

class Type4Conn{

    public static void main(String ar[])throws Exception{

        Properties p=new Properties();



        InitialContext ctx=new InitialContext(p);

        DataSource ds=(DataSource)ctx.lookup("abc");


        Connection con=ds.getConnection();

        Statement st=con.createStatement();

        int a=st.executeUpdate("insert into user values('test','testuser',2)");

        System.out.println(a+" records inserted");




Anonymous said...

Hello. im having problem in connecting my oracle web logic server.

this is my error, how can i resolved this im new in web logic.

Exception in thread "main" java.lang.ClassNotFoundException: weblogic.jndi.rmi.Driver
at$ Source)
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)

Hemraj said...

Add weblogic.jar in classpath.

Popular Posts