Results 1 to 5 of 5
  1. #1
    rmaadil is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default Having problem in connecting with SQL Server 2005

    I am using the following code for getting connection to the SQL Server 2005 Database:

    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");

    I have debuged the code by placing a breakpoint exactly at this line and whenever I step over this statement it generates an exception and then when I print the message in the catch block, I got the following message:

    com.microsoft.jdbc.sqlserver.SQLServerDriver

    which is exactly the string I am passing to the above function.

    Can anybody help me?

  2. #2
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    what exception is that? Do you have the library in the path?
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

  3. #3
    rmaadil is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default

    Can u explain me that how to include the library u r talking about. I am new to java so I don't have much knowledge about the language. Kindly elaborate.

    I will be thankful to u.

  4. #4
    rmaadil is offline Member
    Join Date
    May 2008
    Posts
    9
    Rep Power
    0

    Default Connecting To SQL Server

    Here is the code that I have written to get a connection to the SQL Server. I have also set the classpath. But still I am getting error. I have debugged the code and when I step over the Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver"); it generates an exception and the message that is printed is the string that is the parameter to the function forName. I am struck as I have searched a lot of forums and I haven't found this kind of error. Most of the errors that came due to classpath settings was "drievr cannot be found" but I think my error is not because of the classpath settings. Can anyone help me?

    public class Main {


    public static void main(String[] args) {

    try
    {

    Class.forName("com.microsoft.jdbc.sqlserver.SQLSer verDriver");
    Connection con = DriverManager.getConnection("jdbc:microsoft:sqlser ver://localhost:1433; DATABASENAME = Test","mimdad","aaa");
    }
    catch (Exception e)
    {
    System.out.println(e.getMessage());
    }

    }
    }

  5. #5
    danielstoner's Avatar
    danielstoner is offline Senior Member
    Join Date
    Apr 2008
    Location
    Canada
    Posts
    191
    Rep Power
    7

    Default

    Did you notice you have a space in the name of the class?

    "com.microsoft.jdbc.sqlserver.SQLSer verDriver" !!!

    and also in the URL:

    "jdbc:microsoft:sqlser ver://localhost:1433; DATABASENAME = Test"

    Is that just a typo?

    Read more about what should be in your classpath here: HOW TO: Get Started with Microsoft JDBC
    Daniel @ [www.littletutorials.com]
    Language is froth on the surface of thought

Similar Threads

  1. hibernate support for sql-server 2005
    By javadev in forum JDBC
    Replies: 2
    Last Post: 06-25-2008, 02:48 PM
  2. Connecting to a Web server
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:57 PM
  3. Java connecting to sql server 2005
    By pelegk2 in forum JDBC
    Replies: 0
    Last Post: 04-05-2008, 10:17 PM
  4. Replies: 3
    Last Post: 11-03-2007, 02:58 PM
  5. SQL Server 2005 Jdbc connection
    By mgt83 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 07-27-2007, 05:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •