我是java的新手。使用java创建与MS SQL Server的连接时,我收到以下错误。
Connection failed com.microsoft.sqlserver.jdbc.SQLServerException:
The connection to the host D-PC, named instance sqlexpress failed.
Error: "java.net.SocketTimeoutException: Receive timed out".
Verify the server and instance names and check that no firewall is blocking UDP traffic to port 1434.
For SQL Server 2005 or later, verify that the SQL Server Browser Service is running on the host.
我的代码是
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Jatin
*/
public class SQLConnect {
/* public Connection sqlcon(Connection conn){
return conn;
}*/
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Connection conn =null;
try {
String url = "jdbc:sqlserver://D-PC\\SQLEXPRESS;integratedSecurity=true";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
try {
conn = DriverManager.getConnection(url);
System.out.println("Connection Successful");
} catch (SQLException ex) {
System.out.println("Connection failed" + ex);
}
} catch (ClassNotFoundException ex) {
System.out.println("Connection Failed" + ex);
}
}