Java - Java Microsoft SQl Server 2008 driver - Asked By waseem kaleem on 23-Aug-11 04:25 AM

Class.forName("net.sourceforge.jtds.jdbcx.JdbcDataSource");//it loads successfully
can any one create connection string for DriverManager.getConnection(); method
Thanks
Ravi S replied to waseem kaleem on 23-Aug-11 04:29 AM
HI

Using the DriverManager Class
 
Connecting to your DBMS with the DriverManager class involves calling the method DriverManager.getConnection. The following method, JDBCTutorialUtilities.getConnection, establishes a database connection:
 
  public Connection getConnection() throws SQLException {
  Connection conn = null;
  Properties connectionProps = new Properties();
  connectionProps.put("user", this.userName);
  connectionProps.put("password", this.password);
 
  if (this.dbms.equals("mysql")) {
    conn = DriverManager.
    getConnection("jdbc:" + this.dbms + "://" + this.serverName +
            ":" + this.portNumber + "/", connectionProps);
  } else if (this.dbms.equals("derby")) {
    conn = DriverManager.
    getConnection("jdbc:" + this.dbms + ":" + this.dbName + ";create=true", connectionProps);
  }
  System.out.println("Connected to database");
  return conn;
  }

refer link
http://publib.boulder.ibm.com/infocenter/db2luw/v8/index.jsp?topic=/com.ibm.db2.udb.doc/ad/cjvjt2cn.htm
http://download.oracle.com/javase/tutorial/jdbc/basics/connecting.html
Reena Jain replied to waseem kaleem on 23-Aug-11 04:34 AM
Hi,

Once the JDBC driver class is loaded, you are ready to connect to a SQL Server by using the DriverManager.getConnection(connection_url) method. The connection URL, connection_url, is a string with the following syntax:

jdbc:sqlserver://server_name;user=login;password=****
 
public Connection getConnection() throws SQLException {
  Connection conn = null;
  Properties connectionProps = new Properties();
  connectionProps.put("user", this.userName);
  connectionProps.put("password", this.password);
 
  if (this.dbms.equals("mysql")) {
    conn = DriverManager.
    getConnection("jdbc:" + this.dbms + "://" + this.serverName +
            ":" + this.portNumber + "/", connectionProps);
  } else if (this.dbms.equals("derby")) {
    conn = DriverManager.
    getConnection("jdbc:" + this.dbms + ":" + this.dbName + ";create=true", connectionProps);
  }
  System.out.println("Connected to database");
  return conn;
  }
Anoop S replied to waseem kaleem on 23-Aug-11 04:39 AM

Once the JDBC driver class is loaded, you are ready to connect to a SQL Server by using the DriverManager.getConnection(connection_url) method. The connection URL, connection_url, is a string with the following syntax:

jdbc:sqlserver://server_name;user=login;password=****

The tutorial program below shows you a good example of using getConnection() and connection URL:

/**
 * ConnectionTest2.java
 * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
 */
import java.sql.*;
public class ConnectionTest2 {
  public static void main(String [] args) {
    Connection con = null;
    try {

// Load Microsoft JDBC Driver 1.0
      Class.forName(
        "com.microsoft.sqlserver.jdbc.SQLServerDriver");

// Obtaining a connection to SQL Server
      con = DriverManager.getConnection(
          "jdbc:sqlserver://localhost;"
        + "user=sa;password=HerongYang");

    } catch (java.lang.ClassNotFoundException e) {
      System.err.println("ClassNotFoundException: "
        +e.getMessage());
    } catch (SQLException e) {
      System.err.println("SQLException: "
        +e.getMessage());
    }
  }
}
waseem kaleem replied to waseem kaleem on 24-Aug-11 12:06 AM
My Computer Name is Kaleem
Sql Server Name is KALEEM\SQLEXPRESS
I try This one
Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://KALEEM//SQLEXPRESS:1433/student","waseem","123123");
KALEEM\SQLEXPRESS
and this one
 Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://KALEEM:1433/student","waseem","123123");
and this one
Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection con=DriverManager.getConnection("jdbc:jtds:sqlserver://KALEEM//SQLEXPRESS:1433/student","waseem","123123");
All three methods give IOEXCEPTION Connection refused