0

I am using sql server 2008 r2 sql express. I usually connect to my sql like this: enter image description here

Now I want to connect to sql server 2008 r2 from my eclipse.

I searched google and I found that I have to download a jar file and I did and I added it to my project in eclipse.

my code is

Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            String connectionUrl = "jdbc:sqlserver://localhost:1433;"
                    + "databaseName=DATABASE;user=User-PC\\User;password=;";

To be honest: I don't know if i should put localhost or sqlexpress and I don't know the password because as I should you in the image or I just use it empty.

the exception is :

The TCP/IP connection to the host localhost, port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall.".

I enable TCP/IP in my sql configuration

please help me

4

1 回答 1

0

在此处输入图像描述

创建新用户时,您必须设置该用户的登录名,请检查图像并按彩色按钮,然后选择您的登录名。

之后,将您的字符串 url 连接更改为:

Class.forName(DB_DRIVER_NAME);
            String connectionString = "jdbc:sqlserver://" + DB_SERVER
                    + ";databaseName=" + DB_NAME + ";user=" + DB_USER
                    + ";password=" + DB_PASSWORD;
于 2013-04-28T15:50:43.967 回答