当前位置:网站首页>Eclipse connects to SQL server database "recommended collection"
Eclipse connects to SQL server database "recommended collection"
2022-07-30 14:10:00 【Full stack programmer webmaster】
大家好,又见面了,我是你们的朋友全栈君.
1.准备,下载JDBC驱动程序
To be able to use the database must have a correspondingJDBC驱动程序,然后到Microsoft官网下载https://www.microsoft.com/zh-cn/download/details.aspx?id=11774
下载完成之后
After decompression with decompression tool
Click on that folder and enter
2.配置SQL sever是否可以sa登录,If not, refer to the link below
http://jingyan.baidu.com/article/8cdccae9452b3c315513cd52.html
设置好之后,然后在“我的电脑”右击选择“管理” 接着点击“服务和应用程序”,选择“SQL Sever配置管理器”
3.将下载的sqljdbc42.jardriver in yourjdk中lib目录下
进行连接测试
(1)打开SQL server 数据库,新建一个数据库test.
(2)运行eclipse新建一个project,然后新建一个包,包里新建一个java文件,Main文件
(3)然后将sqljdbc42.jar复制到该project中,选择该文件后,右键点击Build Path
*关于Build Path还可以:右键单击工程名,依次选择 Build Path → Configure Build Path,Select on the right side of the window that opens Libraries标签,然后单击 Add External JARs,找到 sqljdbc42.jar 文件并打开,然后单击 OK Complete the configuration of the build path.
(4)然后进入Main.javafile copy the following code into it
package cn.edu.gues;
import java.sql.*;
public class Main {
public static void main(String [] args)
{
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=test";//test为你的数据库名
String userName="sa";//你的数据库用户名
String userPwd="123";//你的密码
try
{
Class.forName(driverName);
System.out.println("加载驱动成功!");
}catch(Exception e){
e.printStackTrace();
System.out.println("加载驱动失败!");
}
try{
Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("连接数据库成功!");
}catch(Exception e)
{
e.printStackTrace();
System.out.print("SQL Server连接失败!");
}
}
}(5)运行
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128950.html原文链接:https://javaforall.cn
边栏推荐
猜你喜欢

Jenkins自动化部署项目

43.【list链表的定义及初始化】

jsArray array copy method performance test 2207300823

Classic test interview questions set - logical reasoning questions

我为何从开发人员转做测试,3年软件测试工程师,带你聊聊这其中的秘辛

There is a risk of water ingress in the battery pack tray and there is a potential safety hazard. 52,928 Tang DMs are urgently recalled

js男女身高体重关系图

重保特辑|筑牢第一道防线,云防火墙攻防演练最佳实践

百家号取消接口发文功能:插外链获权重被堵死

ENVI图像处理(6):NDVI和植被指数
随机推荐
第十四天笔记
SQL 26 calculation under 25 years of age or older and the number of users
ARC117E零和范围2
[C# 循环跳转]-C# 中的 while/do-while/for/foreach 循环结构以及 break/continue 跳转语句
sql中ddl和dml(sql与access的区别)
CF1677E Tokitsukaze and Beautiful Subsegments
经典测试面试题集—逻辑推理题
高性能数据访问中间件 OBProxy(三):问题排查和服务运维
[论文翻译] Unpaired Image-To-Image Translation Using Cycle-Consistent Adversarial Networks
Shell变量与赋值、变量运算、特殊变量、重定向与管渠
跳槽前,把自己弄成卷王
CF780G Andryusha and Nervous Barriers
电池包托盘有进水风险,存在安全隐患,紧急召回52928辆唐DM
Eleven BUUCTF questions (06)
svg波浪动画js特效代码
mongodb打破原则引入SQL,它到底想要干啥?
记面试外包公司的一次经历,到底该不该去?
权威推荐!腾讯安全DDoS边缘安全产品获国际研究机构Omdia认可
el-table中el-table-column下的操作切换class样式
selenium4+pyetsst+allure+pom进行自动化测试框架的最新设计