I am trying to connect local db sqlserver 2012 but unable to connect. I am using the below code. Please help to solve this issue.
String url = "jdbc:sqlserver://(localdb)\\v11.0;" + "databaseName=sakthi;user=sakthi;password=****;";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection con = DriverManager.getConnection(url);
Statement stmt = con.createStatement();
ResultSet res =stmt.executeQuery("select * from sakthi");
while(res.next()){
System.out.println(res.getString(1));
System.out.println(res.getString(2));
}
I am getting the below error.
com.microsoft.sqlserver.jdbc.SQLServerException: The connection to the host (localdb), named instance v11.0 failed. Error: "java.net.UnknownHostException: (localdb)". 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.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.getInstancePort(SQLServerConnection.java:3589)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.primaryPermissionCheck(SQLServerConnection.java:1225)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:972)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at javaprojects.jdbc.main(jdbc.java:17)