简体   繁体   English

JDBC SQL Server错误:java.sql.SQLException:没有合适的驱动程序

[英]jdbc sql server error: java.sql.SQLException: No suitable driver

I'm using eclipse, trying to connect to a sql server db. 我正在使用eclipse,试图连接到SQL Server数据库。 I have the jars in my build path. 我的构建路径中有jar。 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) java.sql.SQLException:java.sql.DriverManager.getConnection(DriverManager.java:353)处的java.sql.DriverManager.getConnection(DriverManager.java:325)没有合适的驱动程序

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");
       }
    }

Your connection string is wrong. 您的连接字符串错误。 It should be just " jdbc:sqlserver://.... ". 它应该只是“ jdbc:sqlserver://.... ”。 Read more here . 在这里阅读更多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:java.sql.SQLException:未找到适合jdbc:sqlserver的驱动程序 - Error: java.sql.SQLException: No suitable driver found for jdbc:sqlserver java.sql.SQLException:找不到适合jdbc:oracle:thin的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:oracle:thin java.sql.SQLException:找不到适用于jdbc:derby的驱动程序: - java.sql.SQLException: No suitable driver found for jdbc:derby: java.sql.SQLException:找不到适用于jdbc:mysql的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:mysql java.sql.SQLException:找不到适用于jdbc:sqlserver的驱动程序: - java.sql.SQLException: No suitable driver found for jdbc:sqlserver: java.sql.SQLException:没有找到适合 jdbc:microsoft:sqlserver 的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:microsoft:sqlserver java.sql.SQLException:找不到适用于jdbc:sqlite的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:sqlite java.sql.SQLException:找不到适用于jdbc:microsoft的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc:microsoft java.sql.SQLException:找不到适合jdbc的驱动程序 - java.sql.SQLException: No suitable driver found for jdbc java.sql.SQLException:找不到合适的驱动程序jdbc:oracle:thin - java.sql.SQLException: No suitable driver found jdbc:oracle:thin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM