MyEclipse Connecting a SQL Server connection test

Source: Internet
Author: User
Tags microsoft sql server 2005

(1) Run SQL Server Configuration Manager locate the MSSQLSERVER protocol on the left side of the open window, right-click TCP/IP on the right, select "Enabled", and refer to figure 5.7.


Figure 5.7 enabling TCP/IP

(2) on the right side of TCP/IP, in the Pop-up window select the address tag, set the TCP port in Ipall to 1433, and set all the enabled options above to "yes". Refer to Figure 5.8.


Figure 5.8 setting Ipall

(3) The Microsoft SQL Server 2005→ Configuration tool →sql Server surface Area Configurator, in the window that opens, select "Surface Area Configuration for services and connections", select "Remote Connection" on the left side of the open window, and on the right, select "Use both tcp/ IP and Named pipes (B) ", then click" Apply ".

(4) Start menu → Run cmd→ at the command prompt input: Telnet 127.0.0.1 1433, if prompted "Unable to open the connection to the host, on port 1433: Connection Failed", then 1433 port is not open, you need to re-configure the above. If the connection is successful, the interface shown in 5.9 appears.


Figure 5.9 connecting 1433 ports successfully

(5) Download Sqljdbc.jar, and then configure the environment variable CLASSPATH, the variable value is Sqljdbc.jar address on the hard disk, 5.10 is shown.


Figure 5.10 Configuring environment variables

(6) Create a new database, then open myeclipse create a new project, select Build Path→configure build Path in the project, select the Libraries tab on the right side of the open window, and click Add External JARs, Locate the Sqljdbc.jar file and open it, and then click OK to complete the configuration of the build path.

(7) Create a new test class, the key code is as follows:

String drivername = "Com.microsoft.sqlserver.jdbc.SQLServerDriver";

String Dburl = "Jdbc:sqlserver://localhost:1433;databasename=qiaoliang";

String userName = "sa"; Default User Name

String userpwd = "123"; Password

try {

Class.forName (drivername);

Connection dbconn =drivermanager.getconnection (Dburl, UserName,

USERPWD);

SYSTEM.OUT.PRINTLN ("Connection Successful! "); If the connection succeeds, the console output is "connected successfully!" ”

} catch (Exception e) {

System.out.println ("Connection failed! ");

}

(8) Running the project, a successful connection at the console indicates that the MyEclipse connection database test was successful. As shown in 5.11.


Figure 5.11 The database connection was successful

MyEclipse Connecting a SQL Server connection test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.