get Connection from DB2 Database - Java java.sql

Java examples for java.sql:DB2

Description

get Connection from DB2 Database

Demo Code


//package com.java2s;
import java.sql.Connection;
import java.sql.DriverManager;

public class Main {
    public static void main(String[] argv) throws Exception {
        System.out.println(getConnection());
    }//from   w  ww  .j  a v a  2s. c  om

    public static Connection getConnection() {

        String url = "jdbc:db2://localhost:50000/icmpdb:currentSchema=ICMPDB;";
        String user = "db2admin";
        String password = "123**123";
        Connection conn = null;
        try {
            Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
            conn = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
}

Related Tutorials