1

I'm using eclipse, trying to connect to a sql server db. I have the jars in my build path. I get the error:

java.sql.SQLException: No suitable driver at java.sql.DriverManager.getConnection(DriverManager.java:325) at java.sql.DriverManager.getConnection(DriverManager.java:353)

Here is my code:

  import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;

    public class connect
    {
       public void dbConnect(String db_connect_string,
                String db_userid,
                String db_password)
       {
          try {
             Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
             Connection conn = DriverManager.getConnection(db_connect_string,
                      db_userid, db_password);
             System.out.println("connected");
             Statement statement = conn.createStatement();
             String queryString = "select * from sysobjects where type='u'";
             ResultSet rs = statement.executeQuery(queryString);
             while (rs.next()) {
                System.out.println(rs.getString(1));
             }
          } catch (Exception e) {
             e.printStackTrace();
          }
       }

       public static void main(String[] args)
       {
          connect connServer = new connect();
          connServer.dbConnect("jdbc:jtds:sqlserver://ssdd.ffd.aduat.fdd.com:5150", "rre",
                   "wer");
       }
    }
1
  • I think u r trying to use the JTDS URL with the MS SQL driver. What is the jar u have Commented Mar 7, 2011 at 15:22

1 Answer 1

2

Your connection string is wrong. It should be just "jdbc:sqlserver://....". Read more here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.