jdbc sql server错误:java.sql.SQLException:没有合适的驱动程序

时间:2011-03-07 15:19:23

标签: java sql-server eclipse jdbc

我正在使用eclipse,尝试连接到sql server db。我的构建路径中有罐子。我收到错误:

  

java.sql.SQLException:不合适   司机在   java.sql.DriverManager.getConnection(DriverManager.java:325)     在   java.sql.DriverManager.getConnection(DriverManager.java:353)

这是我的代码:

  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 个答案:

答案 0 :(得分:1)

您的连接字符串错误。它应该只是“jdbc:sqlserver://....”。阅读更多here