Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Error connecting to SQl Server with integratedSecurity = true - Windows aut

843859Aug 8 2007
I am getting the following error while trying to access SQL Server database using JDBC with windows authentication instead of standard user id and passwoed. Please help if you have came across such issue.

I have the following setup when I run the following class.
-Djava.library.path="C:\Softwares\jdbc\Microsoft SQL Server 2005 JDBC Driver_1.2\sqljdbc_1.2\enu\auth\x86"

-Shankar

java.sql.SQLException: No suitable driver
Error Trace in getConnection() : No suitable driver
Error: No active Connection
at java.sql.DriverManager.getConnection(DriverManager.java:532)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at com.wachovia.cib.mars.dataextract.configData.Connect.getConnection(Connect.java:28)
at com.wachovia.cib.mars.dataextract.configData.Connect.displayDbProperties(Connect.java:45)
at com.wachovia.cib.mars.dataextract.configData.Connect.main(Connect.java:81)


package com.wachovia.cib.mars.dataextract.configData;

import java.sql.Connection;
import java.util.Properties;
import java.util.logging.Logger;

public class Connect {
	Connection con;
    // Informs the driver to use server a side-cursor, 
    // which permits more than one active statement 
    // on a connection.
    private final String selectMethod = "cursor"; 
    
    // Constructor
    public Connect(){}
    
    private String getConnectionUrl(){
         //return url+serverName+":"+portNumber+";databaseName="+databaseName+";selectMethod="+selectMethod+";";
         return "jdbc:microsoft:sqlserver://MYSERVERNAME:11000";
    }
    
    private java.sql.Connection getConnection(){
    	System.loadLibrary("sqljdbc_auth");
         try{
              Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
              Properties props = new Properties();
              props.setProperty("integratedSecurity", "true");
              con = java.sql.DriverManager.getConnection(getConnectionUrl(),props);
              if(con!=null) System.out.println("Connection Successful!");
         }catch(Exception e){
              e.printStackTrace();
              System.out.println("Error Trace in getConnection() : " + e.getMessage());
        }
         return con;
     }

    /*
         Display the driver properties, database details 
    */ 

    public void displayDbProperties(){
         java.sql.DatabaseMetaData dm = null;
         java.sql.ResultSet rs = null;
         try{
              con= this.getConnection();
              if(con!=null){
                   dm = con.getMetaData();
                   System.out.println("Driver Information");
                   System.out.println("\tDriver Name: "+ dm.getDriverName());
                   System.out.println("\tDriver Version: "+ dm.getDriverVersion ());
                   System.out.println("\nDatabase Information ");
                   System.out.println("\tDatabase Name: "+ dm.getDatabaseProductName());
                   System.out.println("\tDatabase Version: "+ dm.getDatabaseProductVersion());
                   System.out.println("Avalilable Catalogs ");
                   rs = dm.getCatalogs();
                   while(rs.next()){
                        System.out.println("\tcatalog: "+ rs.getString(1));
                   } 
                   rs.close();
                   rs = null;
                   closeConnection();
              }else System.out.println("Error: No active Connection");
         }catch(Exception e){
              e.printStackTrace();
         }
         dm=null;
    }     
    
    private void closeConnection(){
         try{
              if(con!=null)
                   con.close();
              con=null;
         }catch(Exception e){
              e.printStackTrace();
         }
    }
    public static void main(String[] args) throws Exception
      {
         Connect myDbTest = new Connect();
         myDbTest.displayDbProperties();
      }

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 5 2007
Added on Aug 8 2007
0 comments
208 views