get MS SQL Server 2000 Connection - Java java.sql

Java examples for java.sql:SqlServer

Description

get MS SQL Server 2000 Connection

Demo Code


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

public class Main {
    public static Connection getMSSQL2000Con(String server, String db,
            String uid, String pwd) {
        try {//from ww w  .j  a v  a  2 s  .c o m
            Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
            // set this to a MS SQL Server
            String database = "jdbc:microsoft:sqlserver://" + server
                    + ":1433;";
            database += "databasename=" + db + ";user=" + uid
                    + ";password=" + pwd + ";";
            // now we can get the connection from the DriverManager
            return DriverManager.getConnection(database);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}

Related Tutorials