I have to access DB2 database in plain stand alone Java project.

I am unable to use datasource from container right? Should i write JDBC connection?

JDBC connection

You must have necessary db2 JDBC jars inside your program's compile time, runtime classpath. For those who have native DB2 client placed on target machines, you can utilize JDBC ODBC Bridge. However, better to stick to pure Java- type4 motorists. (db2jcc.jar, db2jcc_license*.jar etc)

When the motorists have been in classpath, you can utilize usual JDBC code to begin with. For example:

import java.sql.*;
import java.lang.*;
import java.io.*;
import Com.ibm.db2.jcc.*;  //Type4 library
public class DB2Sample{
  static
  {
    try 
    {       

      Class.forName("com.ibm.db2.jcc.DB2Driver");
    } 
    catch (ClassNotFoundException e)
    {
       System.err.println("Could not load DB2 driver \n");
       System.err.println(e.getMessage());
       System.exit(1);
    }

public static void main(String args[]) 
  {

    /* Type 4 driver url */
    String url = "jdbc:db2j:net://machine-name:port-number/TGSAMPLE";
         Connection conn = DriverManager.getConnection(url,"userid", "psswrd");
...
  }

and so forth.

Take a look at IBM documentation here for better examples and details

Based on your requirements, either handle a JDBC connection yourself or make use of a stand alone JDBC pool e.g. C3P0, DBCP or BoneCP.

I am unable to use datasource from container right? Should i write JDBC connection?

You can test to obtain the connection in the container using JNDI Research. For example see this.

But It could be much simpler not get it done.

Should i write JDBC connection?

Yes, whether it's simpler that you should manage the bond oneself.

You may also make use of a connection pool for example Apache DBCP or C3PO. Here's a list of others that support Connection pooling for stand alone application