gpt4 book ai didi

java - 使用jdbc连接sql server错误

转载 作者:行者123 更新时间:2023-12-01 10:52:26 26 4
gpt4 key购买 nike

我尝试了下面的代码,但收到此错误:

java.sql.SQLException: No suitable driver found for jdbc:sqlserver://Usatlbyq.na.ko.com:1433;integratedSecurity=true;
at java.sql.DriverManager.getConnection(DriverManager.java:689)
at java.sql.DriverManager.getConnection(DriverManager.java:270)
at testing.testingsql.main(testingsql.java:19)

我正在使用以下代码:

package testing;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class testingsql {
public static Connection conn = null;
//private String dbName = null;


public static void main(String[] args) throws IOException {

try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
conn = DriverManager.getConnection("jdbc:sqlserver://Usatlbyq.na.ko.com:1433;integratedSecurity=true;");//here put the new simple url.
System.out.println("succesful connection");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ResultSet runSql(String sql) throws SQLException {
Statement sta = conn.createStatement();
return sta.executeQuery(sql);
}

}

最佳答案

您的 URL 应为 jdbc:sqlserver://server:port;DatabaseName=dbname

关于java - 使用jdbc连接sql server错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33775922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com