i try to connect to my local sqlserver express 2008 R2.
when i specify server name as 127.0.0.1 , like
String url = "jdbc:sqlserver://127.0.0.1;databaseName=mydatabase;";
i can connect.
but when i write servername\named instance as server name like
String url = "jdbc:sqlserver://machinename//instancename;databaseName=mydatabase;";
then i couldnt connect to server.
configurations: i set tcp/ip connection enabled. i set to tcp dynamic ports as 1433 in ipall section. named instance -> enabled , it doesnt affect connection.
package demojdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;
import java.util.Iterator;
/**
*
* @author ttn
*/
public class DemoJdbc {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
baglanti();
}
public static void baglanti() {
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
System.out.println("driver yuklendi");
} catch (ClassNotFoundException e) {
System.out.println("Drive bulunmadi"+e);
}
Connection con = null;
String url = "jdbc:sqlserver://127.0.0.1;databaseName=mydatabase;";
try {
con= DriverManager.getConnection(url, "xxx","xxx");
System.out.println("Veritabanına baglantı kuruldu");
Statement stmt=con.createStatement();
} catch (Exception e) {
System.out.println("Hata Var"+e);
}
}
}