get DB2 Connection - Java java.sql

Java examples for java.sql:DB2

Description

get DB2 Connection

Demo Code


//package com.java2s;
import java.sql.*;

public class Main {
    public static Connection getDB2Connection(String server, String db,
            String uid, String pwd) {
        String sConnect;//from  w w w  .ja v  a 2 s.c  o m

        sConnect = "jdbc:db2://" + server + ":50000/" + db;
        try {
            Class.forName("com.ibm.db2.jcc.DB2Driver");
            Connection con = java.sql.DriverManager.getConnection(sConnect,
                    uid, pwd);
            return con;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials