Reputation: 1
package payroll;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class tables {
public static void main(String[] args) throws ClassNotFoundException, SQLException{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = "jdbc:sqlserver://DESKTOP-4HE4VKM\\\\SQLEXPRESS;DatabaseName=payroll;integratedSecurity=true;encrypt=false;";
try (Connection connect = DriverManager.getConnection(connectionUrl); Statement st = connect.createStatement();)
{
ResultSet rs = st.executeQuery("select from EMPLOYEE");
while (rs.next()) {
System.out.println (rs.getString(("EmpName")));
}
}
catch (SQLException e)
{
System.out.println ("Error");
e.printStackTrace();
}
}
}
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host DESKTOP-4HE4VKM, 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.
For some reason I keep getting this error and I am not really sure how to resolve this.
Upvotes: 0
Views: 360
Reputation: 994
You should inform the instante name :
jdbc:sqlserver://DESKTOP-4HE4VKM;instanceName=SQLEXPRESS;DatabaseName=payroll;integratedSecurity=true;encrypt=false
Upvotes: 0