Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Eclipse connect to SQL Server

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "Eclipse how to connect SQL Server", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Eclipse how to connect SQL Server" bar!

The software version and related environment used in this article:

Eclipse Photon Release (4.8.0)

JDK-10.0.2

SQL Server 2012

1. Configure SQL Server 2012

Open SQL Server Management Studio and log in using SQL Server authentication:

If you choose Windows authentication login method when installing SQL Server 2012, you need to reset it. Refer to: "SQL Server login change [Windows authentication] to [SQL Server authentication]"

After logging in successfully, open the SQL Server configuration Manager:

Find the SQL Server network configuration on the left, click the protocol of "your Database name", and right-click all the Shared Memory, Named Pipes and TCP/IP in the right column to enable:

Double-click TCP/IP (or right-select property), select [IP address], and set the [IP address] of [IP1] and [IP10] to 127.0.0.1

Set [enabled] to Yes for all [IPx] (IP1, IP10, IP11, IP12, etc.)

Drop down to the bottom of the window, set the [TCP port] in [IPAll] to 1433, and leave the rest unchanged.

two。 Enable the Telnet service

Open [Control Panel], select "programs", click "enable or disable Windows", find "Telnet Client", check and save, and check "Telnet Server" and "Telnet client" for versions of Windows 7 or below.

3. Test whether port 1433 is open

Run cmd and enter telnet 127.0.0.1 1433. If you are prompted that the connection failed, port 1433 is not open. You need to reconfigure the above. If the connection is successful, it will be displayed as follows:

4. Download JDBC

Click here to download each version of JDBC. Different versions of JDBC drivers are applicable to different JAR and different versions of SQL. For more information, please see "Microsoft SQL Server JDBC driver support Matrix". For example, using SQL Server 2012, we can download version 6.0and download sqljdbc_6.0.8112.200_chs.tar.gz files. After decompression, you can find sqljdbc41.jar and sqljdbc42.jar files. When using it, you should pay attention to which version of your JDK is, and those above 1.80 correspond to sqljdbc42.jar class libraries.

5.Eclipse connection SQL Server

Put sqljdbc41.jar or sqljdbc42.jar in a folder, open Eclipse, in the project that needs to connect to the database, right-click [src], select [Build Path], [Configure Build Path … ], select [Libraries] in the pop-up window, select [Modulepath], and click [Add External JARs... ], find the downloaded sqljdbc41.jar or sqljdbc42.jar file and open it, and then [Apply and Close] save

6. Test connection

Open SQL Server 2012 and create a new database test

In Eclipse, create a new package and a new class under the project to test the database connection:

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

Package test

Import java.sql.*

Public class Main {

Public static void main (String [] args)

{

String driverName= "com.microsoft.sqlserver.jdbc.SQLServerDriver"

String dbURL= "jdbc:sqlserver://localhost:1433;DatabaseName=test"; / / the name of the database to connect to

String userName= "sa"; / / Database user name

String userPwd= "000000"; / / Database password

Try

{

Class.forName (driverName)

Connection dbConn=DriverManager.getConnection (dbURL,userName,userPwd)

System.out.println ("connect to database successfully")

}

Catch (Exception e)

{

E.printStackTrace ()

System.out.print ("connection failed")

}

}

}

If all of the above are correct, you can successfully connect to the database:

Thank you for your reading, the above is the content of "how to connect Eclipse to SQL Server", after the study of this article, I believe you have a deeper understanding of how to connect Eclipse to SQL Server, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report