java - 无法使用 JDBC 连接到 SQL Server
问题描述
我在使用 Netbeans 中的 JDBC 驱动程序连接到数据库服务器时遇到问题。我已经尝试了一切,启用 TCP/IP,打开端口,我已经按照在线教程进行操作。它只是行不通。
这是我在控制台中收到的错误消息:
Information: Error: The TCP / IP connection could not be made to the MANUEL-PC host, port 1433. Error: "Connection refused: connect Verify the connection properties, check that there is an instance of SQL Server running on the host and accepting TCP / IP connections on the port and verify that there is no firewall blocking TCP connections on the port. "
我们正在使用的课程开始...
public class DBPosteo
{
private final String URL ="jdbc:sqlserver://MANUEL-PC\\SQLEXPRESS:1433;databaseName=DLC_MotorDeBusqueda;integratedSecurity=true";
private Connection con;
String query = "";
PreparedStatement pstmt;
ResultSet rs;
public void init()
throws ClassNotFoundException, SQLException
{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
con = DriverManager.getConnection(URL);
}
SQL Management Studio 中的数据库服务器名称
在此先感谢您的帮助...我一生中从未在数据库方面如此挣扎:)
解决方案
删除端口号。
仅指定实例名称 ( SQLEXPRESS
)或端口号 ( 1433
),切勿同时指定两者。
由于端口1433
是为未命名的实例保留的,因此SQLEXPRESS
命名实例将位于不同的端口上,除非您专门配置它(不太可能),否则该端口是动态的并且可以在重新启动时更改,因此您需要命名查找。
推荐阅读
- javascript - 对象值中的Javascript传递函数
- python - Keras 服装回调。生成精确召回时,_flow_index 出现错误
- express - 如何找出访问者在我的网站上停留的时间(持续时间)
- perl - 计算特定子字符串之间的匹配
- php - 如何在 php 中执行 scrapy 脚本?
- python - 散景:绘制多个图形时的跨度
- css - CSS媒体查询选择宽度间隔的补码
- python - Python 2.7.6:使用 pip install 时“没有名为 etree.ElementTree 的模块”
- asp.net - '从'System.DateTime'到'System.TimeSpan'的无效转换。'
- kotlin - 无法使用 Kotlin 编译内联函数