Search This Blog

Sunday, 10 March 2013

Weblogic JDBC Interview Questions


1.JNDI?

   Java Naming and Directory Interface.

   It is an API for accessing different naming and directory services uniformly.
   A naming service associates names with objects and finds objects based on their given names.

2.DATA SOURCE?

   provides a way for jdbc client to obtain a database connection from a connection pool.

3.CONNECTION POOL?

   It is a group of ready-to-use database connections associated with a datasource.

4.DIFFERENCE BETWEEN XA AND NONXA DRIVER TYPES?
 
  An XA transaction, in the most general terms, is a "global transaction" that may span multiple resources.
  A non-XA transaction always involves just one resource.

  An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction.
  Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).

5.DIFFERENCE BETWEEN DATASOURCE AND MULTIDATASOURCE?

  Datasource provides a way for jdbc client to obtain a database connection from a connection pool.
  Multidata source is group of data sources that you can set up according to either a fail over or load balancing algorithm.

6.EXPLAIN DIFFERENT TYPES OF DRIVERS?

  There are 4 types of drivers.
 
  Type 1 Drivers: It is a JDBC - ODBC bridge.usually runs on windows and requires ODBC driver to be installed in client machine.

  Type 2 Drivers:  Requires native driver to be already installed on the client machine. Driver converts JDBC calls to native API calls of database.

  Type 3 Drives: Network server can apply several techniques to boost performance of connection pooling,load management,caching.

  Type 4 Drivers: All java driver Implementations that donot require client side configerartion.

7.STEPS FOR CREATING DATA SOURCE AND CONNECTION POOL IN CONSOLE?
 
  1.click on services
    click on jdbc
    click on datasources
  2.click on lock and edit
    click on new
  3.Provide jdbc datasource properties
    Name,Jndi name,Database type,Driver type
  4.Select one phase commit in "Transaction options"
  5.Create connectionpool in connection properties
    Database name,Hostname,port number,Database username,Password.
  6.Test cofigeration
    Message will display as "connection test succeeded"
  7.Select targets
    Finish and activate changes.


8.WLST SCRIPT FOR CREATING DATASOURCE AND CONNECTION POOL?


  from java.util import *
from javax.management import *
import javax.management.Attribute

print 'Starting the script .... '

connect('system','weblogic','t3://localhost:7001')

# Check if dizzyworldDS data source already exists
try:
cd('/JDBCSystemResources/dizzyworldDS')
print 'The dizzyworldDS data source already exists.'
exit()
except WLSTException:
pass


print 'Changing to edit mode...'


edit()
startEdit()

# creating JDBC resources

jdbcSR = create('dizzyworldDS','JDBCSystemResource')
theJDBCResource = jdbcSR.getJDBCResource()

connectionPoolParams = theJDBCResource.getJDBCConnectionPoolParams()
connectionPoolParams.setInitialCapacity(5)
connectionPoolParams.setMaxCapacity(15)
connectionPoolParams.setCapacityIncrement(5)
connectionPoolParams.setTestTableName('SYSTABLES')
connectionPoolParams.setLoginDelaySeconds(1)

dsParams = theJDBCResource.getJDBCDataSourceParams()
dsParams.addJNDIName("dizzyworldDS")
theJDBCResource.setName("dizzyworldDS")

driverParams = theJDBCResource.getJDBCDriverParams()
driverParams.setUrl('jdbc:pointbase:server://localhost:9092/HRDATABASE')
driverParams.setDriverName('com.pointbase.jdbc.jdbcUniversalDriver')
driverProperties = driverParams.getProperties()

proper = driverProperties.createProperty('user')
proper.setName('user')
proper.setValue('PBPUBLIC')

proper1 = driverProperties.createProperty('databaseName')
proper1.setName('databaseName')
proper1.setValue('jdbc:pointbase:server://localhost:9092/HRDATABASE')

driverParams.setPassword('PBPUBLIC')

# targeting the resources to the Managed Server called dizzy1

cd('/')
tgtServer = getMBean("/Servers/dizzy1")
tgtServer.setJavaCompiler("javac")
tgtServer.setListenAddress("localhost")
tgtServer.setListenPort(7003)
tgtServer.setInstrumentStackTraceEnabled(1)


jdbcSR.addTarget(tgtServer)


save()
activate()
disconnect()

print 'End of script, exiting WLST...'
exit()


9.HOW TO RESET A CONNECTION POOL? PURPOSE OF RESETING CONNECTION POOL?

  1.click on services in admin console
  2.click on jdbc
  3.click on datasources
  4.select the datasource and click on control
  5.now click on reset

  The connection pool goes out of resource is very common issue we usually face across all types of applications.
  As there are plenty of reasons for the same like application is not closing the connections, concurrent user access of DB resources etc.
  When WebLogic Server starts, connections from the connection pools are opened and are available to all clients.
  When a client closes a connection from a connection pool, the connection is returned to the pool and becomes available for other clients;
  the connection itself is not closed. There is little cost to opening and closing pool connections.

10.HOW TO TEST A CONNECTION POOL?
   
  1. click on services
     click on jdbc
     click on datasources
  2. click on lock and edit
     click on new
  3. Provide jdbc datasource properties
  4. Create connectionpool in connection properties
   
  5. click on Test cofigeration
     Message will display as "connection test succeeded"
 

11.CONNECTION POOL PROPERTIES?

   The connection pool properties are Initial size,maximum capacity, capacity increment,login delay,database name,host name,port number,database username,password etc.

12.EXPLAIN ABOUT TWO TIER AND MULTI TIER ARCHITECTURES?

   TWO-TIER ARCHITECTURE: In two tier java application communicates directly with the DBMS.
                          A JDBC driver is needed that can communicate directly with the DBMS.

   MULTI-TIER ARCHITECTURE: In multi tier commands are sent to a middle tier of serviceswhich then sends the commands.
                            DBMS process the commands and sends the results back to middle tier,which then sends them to client.

13.EXPLAIN MULTI DATA SOURCE ALGORITHMS?

   FAIL OVER : connection requets are sent to the first data source in the list.If the request fails, The request is sent to the next data source in the list.

               The process repeated until a valid connection is obtained.or until the end of the list is reached,in which case an exception is thrown.

   LOAD BALANCING : Multi data source distributes connection requests evenlyto its member datasources.Multi data sources that use the load balancing algorithm
             
                    also fail over to the next connection pool in the list if a connection request fails.



                       



























 



 

5 comments:

Unknown said...

very much helpful ....thanks pavan

Unknown said...

very much helpful ...thanks pavan

Anonymous said...

thankyou very much..

Anonymous said...

I have 10 MS. If i create 15 Datasouce and define 100 connections pool....how many DB connections can be achieved?

Vijay Singh Rajawat said...

Good Content, helped me for an interview. thanks