Home Database Mysql Tutorial 链接Eclipse和SQL SEVER_MySQL

链接Eclipse和SQL SEVER_MySQL

May 30, 2016 pm 05:09 PM
Link

一.本文内容

 

讲诉使用JDBC建立Eclipse和Sql sever的桥梁的过程与其中可能遇见的问题。

 

二.详细内容

 

1.JDBC驱动的下载

 

建议一定要上与SQL SEVER相关的微软官网下载,以便找到最适合自己手中sql的版本驱动

 

本文我使用的是windows.10操作系统,SQL SEVER 2014 EXPRESS(设置了管理员登陆密码),Eclipse(已配置好JDK)

 

截至至(2015年11月11日)

 

最新的驱动微软下载地址为:https://www.microsoft.com/zh-cn/download/details.aspx?id=11774

 

Microsoft JDBC Driver 的主页为:https://msdn.microsoft.com/en-us/data/aa937724.aspx

 

2下载解压

 

依照下载页面的系统要求和安装说明下载并安装适合自己操作系统的驱动版本。

链接Eclipse和SQL SEVER_MySQL

为避免不必要的麻烦需要额外注意的是安装说明中:

 

3.找到所需要导入Eclipse的驱动文件

 

1.在eclipse中创建好一个JAVA项目和一个带main函数的类(过程在此不再演示)

 

2.在项目中新建一个文件夹(名字随意就好,这里为了方便,就名为lib)。

 

3.在解压好的JDBC文件夹(Microsoft JDBC Driver 4.2 for SQL Server)中

 

按以下路径找到chs文件夹:Microsoft JDBC Driver 4.2 for SQL Server\sqljdbc_4.2

 

打开chs文件下,在下面的文件中,找到适合自己版本的后缀名为“.jar”的文件

 

在这里我选择的是 sqljdbc42.jar 驱动文件

链接Eclipse和SQL SEVER_MySQL

4.将jar文件导入Eclipse

 

1.复制上一步找到的.jar文件

 

2.换回eclipse,右键点击新建好的lib文件夹

 

3.将jar文件粘贴进lib文件

 

4.右键点击lib文件夹中的jar文件

 

5.选择  构建路径-->>配置构建路径(英文单词我忘了,不过这一选项位置在红色XX的下面,单词旁边的括号里的是B的选项)

 

导入后的情景如下:

链接Eclipse和SQL SEVER_MySQL

5.在Eclipse中的工作算是完成了,现在完成在sql sever 中的工作(在这里默认大家都会建表建数据库,就不对过程进行过多阐述)

 

1.为了方便,以数据库管理员(sa)身份登陆连接

 

2.建立一个数据库,这里为了方便,名为:“AdventureWorks”

 

3.在“AdventureWorks”数据库中建立一张表:为了方便,名为“S”。

 

4.如果不是使用T—SQL语句建立的“S”表,还需对表进行设计。

 

5.对表“S”进行插入数据。

 

6.至此,顺利的话,都不需要再碰SQL sever 了,不然的话,接下来在说。

 

7.已下是我建立的示例表:

链接Eclipse和SQL SEVER_MySQL

6.回到Eclipse,对数据库进行测试连接。

 

1.根据如下示例输入代码

 

2.注意看代码注释

 

注意:import的包名和package的包名,除非你建立的和我一样,不然,请勿随意“Crrl+c”和“Ctrl+v”。

 

 1 package helloworld;  //包名
 2 
 3 //导入的包名
 4 import java.sql.Connection;
 5 import java.sql.DriverManager;
 6 import java.sql.ResultSet;
 7 import java.sql.Statement;
 8 
 9 //类名
10 public class kelion {
11 
12     //1433是TCP端口
13     //databaseName是数据库名称
14     //user是sql管理员的登陆名(默认的sa)
15     //密码依照自己实际情况填写,这里的“*”是示范(想要我的密码,想得美)
16     
17     static String connectionUrl = "jdbc:sqlserver://localhost:1433;" 
18                +"databaseName=AdventureWorks;"
19                + "user=sa;"
20                + "password=******;";
21             
22     //主函数
23     public static void main(String[] args) throws Exception{
24         // TODO 自动生成的方法存根
25         
26         //注册驱动程序所需语句
27         Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
28         Connection con = DriverManager.getConnection(connectionUrl);
29         
30         Statement stmt = con.createStatement();
31         //从 “S”表中查询 “Sno”列和“Ssex”列
32         ResultSet rs = stmt.executeQuery("select Sno,Ssex from S");
33         
34         //如果查到有数据,全部输出
35         while(rs.next()){
36             System.out.println(rs.getString("Sno")+","+rs.getString("Ssex"));
37         }
38     }
39 
40 } 
Copy after login

 

7.点击Eclipse的运行按钮(别问是小虫,还是播放按钮!!)

 

运行结果如下:

链接Eclipse和SQL SEVER_MySQL

如果你也看到了上图,恭喜,你可以直接点击右上角或滑动到最后。

 

不然,你也可以吐槽后关掉或者接着往下看

 

三.遇到了问题?

 

常见问题:

 

问题提示:

 

通过端口 1433 连接到主机 localhost 的 TCP/IP 连接失败。错误:“Connection refused: connect。。。。。。

 

解决方法:

 

1、打开Sql server 管理配置器(相信会看到到这的都知道到哪找它,万一不知道,度娘会说话)

 

2、点击MSSQLSERVER的协议,在右侧的页面中选择TCP/IP协议

链接Eclipse和SQL SEVER_MySQL

3、右键点击TCP/IP协议,选择“属性”,需要修改连接数据库的端口地址

 

4、跳出来的对话框,里面有好多TCP/IP的端口,找到“IP3”,更改IP地址 为自己电脑的IP地址(或者是127.0.0.1) 在TCP端口添加1433,然后单击应用

链接Eclipse和SQL SEVER_MySQL

5、修改“IPALL”的所有端口改成“1433”(还是这个界面,往下拉滚动条)

链接Eclipse和SQL SEVER_MySQL

6、重新启动服务

链接Eclipse和SQL SEVER_MySQL

7.回到Eclipse,再次点击运行一般就可以看到出运行结果了。

 

如果说你的服务里没有右侧的选项,可以就输数据库安装不完全或出错,解决方法,在此就不描述了。

 

如果说经过以上步骤,还是一样的错误信息提示,那请检查防火墙等错误提示显示的其它可能的出错处(或者寻求周围人帮助,总之不怪我就行,哈哈)。

 

8.以上解决方法同样适用于数据库无法登陆,在与SQLServer建立连接时出现与网络相关的或特定于实例的错误

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use magnet links How to use magnet links Feb 18, 2024 am 10:02 AM

Magnet link is a link method for downloading resources, which is more convenient and efficient than traditional download methods. Magnet links allow you to download resources in a peer-to-peer manner without relying on an intermediary server. This article will introduce how to use magnet links and what to pay attention to. 1. What is a magnet link? A magnet link is a download method based on the P2P (Peer-to-Peer) protocol. Through magnet links, users can directly connect to the publisher of the resource to complete resource sharing and downloading. Compared with traditional downloading methods, magnetic

How to download links starting with 115://? Download method introduction How to download links starting with 115://? Download method introduction Mar 14, 2024 am 11:58 AM

Recently, many users have been asking the editor, how to download links starting with 115://? If you want to download links starting with 115://, you need to use the 115 browser. After you download the 115 browser, let's take a look at the download tutorial compiled by the editor below. Introduction to how to download links starting with 115:// 1. Log in to 115.com, download and install the 115 browser. 2. Enter: chrome://extensions/ in the 115 browser address bar, enter the extension center, search for Tampermonkey, and install the corresponding plug-in. 3. Enter in the address bar of 115 browser: Grease Monkey Script: https://greasyfork.org/en/

How to get the WeChat video account link? How to add product links to WeChat video account? How to get the WeChat video account link? How to add product links to WeChat video account? Mar 22, 2024 pm 09:36 PM

As part of the WeChat ecosystem, WeChat video accounts have gradually become an important promotion tool for content creators and merchants. Getting links to video accounts on this platform is crucial for sharing and disseminating content. The following will introduce in detail how to obtain the WeChat video account link and how to add product links to the video account to improve the dissemination effect of the content. 1. How to get the WeChat video account link? After posting a video on your WeChat video account, the system will automatically create a video link. Authors can copy the link after publishing to facilitate sharing and dissemination. After logging in to your WeChat video account, you can browse the homepage of your video account. On the home page, each video is accompanied by a corresponding link so you can copy or share it directly. 3. Search video account: Enter the video account name in the WeChat search box

How to connect Apple Notes on iPhone in the latest iOS 17 system How to connect Apple Notes on iPhone in the latest iOS 17 system Sep 22, 2023 pm 05:01 PM

Link AppleNotes on iPhone using the Add Link feature. Notes: You can only create links between Apple Notes on iPhone if you have iOS17 installed. Open the Notes app on your iPhone. Now, open the note where you want to add the link. You can also choose to create a new note. Click anywhere on the screen. This will show you a menu. Click the arrow on the right to see the "Add link" option. click it. Now you can type the name of the note or the web page URL. Then, click Done in the upper right corner and the added link will appear in the note. If you want to add a link to a word, just double-click the word to select it, select "Add Link" and press

How to stop Outlook from opening links in Edge browser How to stop Outlook from opening links in Edge browser Aug 03, 2023 am 11:49 AM

How to Stop Outlook from Opening Links in Edge Before proceeding, make sure your preferred browser is set as the default browser in Windows. This ensures that the Outlook link opens in the desired browser. To check and set your default browser: For Windows 10: Click the Start menu and select Settings Go to Apps and then Default Apps Look for "Web Browser" at the bottom of the list of default apps ” If your preferred browser is listed, you’re all set. If Microsoft Edge is listed, click on it and select your preferred browser from the list. If prompted, click Switch Anyway. Fix Edge issues

What are the requirements for a video link? How to link the video account with goods? What are the requirements for a video link? How to link the video account with goods? Mar 07, 2024 pm 01:13 PM

With the popularity of short video platforms, more and more creators are beginning to use video accounts to create and promote content. Video accounts can not only showcase personal talents, but also realize commercial monetization through product links. However, to add a link to a video account, certain conditions must be met. 1. What are the requirements for a video link? Video account authentication is a prerequisite for adding links to your video account. Currently, major short video platforms such as Douyin and Kuaishou provide certification services, which mainly include two types: personal certification and institutional certification. Personal certification requires the submission of real identity information, while institutional certification requires the provision of certification materials from relevant companies or organizations. After completing the authentication, users can add links to their video accounts to enhance the credibility and authority of their accounts. One of the video link

How to link on Doudian - Tutorial on linking on Doudian How to link on Doudian - Tutorial on linking on Doudian Mar 06, 2024 am 08:40 AM

Many friends still don’t know how to link on Doudian, so the editor below will explain the tutorial on how to link on Doudian. If you are in need, hurry up and take a look. I believe it will be helpful to everyone. Step 1: First open the Doudian computer terminal and enter "Window Product Management" on the left column, as shown in the picture. Step 2: Then click "Add Product" in the upper right corner, as shown in the picture. Step 3: Then copy and paste our product link, as shown in the picture. Step 4: Then click "Confirm Add", as shown in the picture. Step 5: Finally enter the introduction, pictures and other information, and then click "Confirm" to link on Douyin, as shown in the picture. The above is the entire content of how to add links to Doudian brought to you by the editor. I hope it can be helpful to everyone.

Why does Google Chrome prompt that your link is not a private link? Why does Google Chrome prompt that your link is not a private link? Mar 08, 2024 am 08:49 AM

Why does Google Chrome prompt "Your link is not a private link"? Some users have encountered that after upgrading to a new version of Google Chrome, they cannot open https-type websites. The following is a solution to the problem that your link is not a private link. Let’s learn about it with the editor. Your link is not a private link Solution: After upgrading to the new version of Google Chrome, you may encounter the prompt "Your connection is not a private connection" when opening an https website, resulting in the inability to access the website. This situation can be confusing, especially if you have been using the Internet for a long time. Next, there are two main solutions: Method 1: First: Start--Run--MMC. Second: Click File--Add Delete Management Unit, drop down to select: Certificate--Add Third.

See all articles