Results 1 to 8 of 8
  1. #1
    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());
    }

    }
    }

  2. #2
    felixtfelix is offline Member
    Join Date
    Dec 2007
    Location
    Mumbai, India
    Posts
    37
    Rep Power
    0

    Default

    hi,

    You have to add sqljdbc.jar to your classpath. That is the file which will connect with database with JDBC driver. Any queries please feel free.

    Regards

    Felix T

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

    Default

    I have used the following command in the command prompt to set the classpath but its not working yet. Help me ASAP

    set classpath=C:\Program Files\Microsoft SQL Server 2005 JDBC Driver\sqljdbc_1.2\enu\sqljdbc.jar

  4. #4
    felixtfelix is offline Member
    Join Date
    Dec 2007
    Location
    Mumbai, India
    Posts
    37
    Rep Power
    0

    Default

    Hi,

    It seems that you are connecting with SQL SERVER 2000. So add the following three files to the class path

    1.Add the follwing files in the classpath
    1.msbase.jar
    2.mssqlserver.jar
    3.msutil.jar


    Regards

    Felix

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

    Default

    I am connecting with SQL Server 2005.

  6. #6
    felixtfelix is offline Member
    Join Date
    Dec 2007
    Location
    Mumbai, India
    Posts
    37
    Rep Power
    0

    Default

    hi,

    Then you have to use the following DBDRIVER

    com.microsoft.sqlserver.jdbc.SQLServerDriver

    Regards
    Felix

  7. #7
    erichua's Avatar
    erichua is offline Member
    Join Date
    May 2008
    Posts
    4
    Rep Power
    0

    Default

    your driver name is strange, make sure your driver jar and the driver name are corret.

  8. #8
    herfnai is offline Member
    Join Date
    Aug 2008
    Posts
    13
    Rep Power
    0

    Default

    hello you must make odbc and:
    Connection cn=null;
    Statement stm=null;
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    cn=DriverManager.getConnection("jdbc:odbc:database name");
    stm=cn.createStatement(ResultSet.TYPE_SCROLL_SENSI TIVE,
    ResultSet.CONCUR_UPDATABLE);
    JOptionPane.showMessageDialog(null,"connected");

    }catch(Exception e)
    {JOptionPane.showMessageDialog(null,"eroor" +"\n"+e.getMessage());


    }

Similar Threads

  1. Replies: 4
    Last Post: 05-21-2008, 07:55 AM
  2. Connecting to a Web server
    By Java Tip in forum java.net
    Replies: 0
    Last Post: 04-07-2008, 08:57 PM
  3. Connecting to a database
    By peiceonly in forum New To Java
    Replies: 2
    Last Post: 04-06-2008, 03:28 PM
  4. Java connecting to sql server 2005
    By pelegk2 in forum JDBC
    Replies: 0
    Last Post: 04-05-2008, 10:17 PM
  5. Who will know like connecting from Websphere
    By Albert in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 06-27-2007, 04:41 PM

Posting Permissions

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