当前位置:网站首页>eclipse连接SQL server数据库「建议收藏」
eclipse连接SQL server数据库「建议收藏」
2022-07-30 13:40:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
1.准备,下载JDBC驱动程序
要能够使用数据库就要有相应的JDBC驱动程序,然后到Microsoft官网下载https://www.microsoft.com/zh-cn/download/details.aspx?id=11774
下载完成之后
用解压工具解压之后
点击该文件夹然后进入
2.配置SQL sever是否可以sa登录,如果不是参考以下链接
http://jingyan.baidu.com/article/8cdccae9452b3c315513cd52.html
设置好之后,然后在“我的电脑”右击选择“管理” 接着点击“服务和应用程序”,选择“SQL Sever配置管理器”
3.将下载的sqljdbc42.jar驱动程序放在你的jdk中lib目录下
进行连接测试
(1)打开SQL server 数据库,新建一个数据库test。
(2)运行eclipse新建一个project,然后新建一个包,包里新建一个java文件,Main文件
(3)然后将sqljdbc42.jar复制到该project中,选择该文件后,右键点击Build Path
*关于Build Path还可以:右键单击工程名,依次选择 Build Path → Configure Build Path,在打开的窗口的右边选择 Libraries标签,然后单击 Add External JARs,找到 sqljdbc42.jar 文件并打开,然后单击 OK 完成构建路径的配置。
(4)然后进入Main.java文件将以下代码复制进入
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
边栏推荐
- Study Notes - Becoming a Data Analyst in Seven Weeks "Week 2: Business": Business Analysis Metrics
- No-code development platform all application settings introductory tutorial
- ENVI图像处理(6):NDVI和植被指数
- Self-tuning PID self-tuning control 】 【
- How awesome is the "12306" architecture?
- 永州动力电池实验室建设合理布局方案
- Data Middle Office Construction (5): Breaking Enterprise Data Silos and Extracting Data Value
- LeetCode二叉树系列——144.二叉树的最大深度
- R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、设置label.select参数自定义在图中显示标签的基因类型(自定义显示的标签列表)
- LeetCode二叉树系列——116.填充每个节点的下一个右侧指针
猜你喜欢

Self-tuning PID self-tuning control 】 【

selenium4+pyetsst+allure+pom进行自动化测试框架的最新设计

How awesome is the "12306" architecture?

Classic test interview questions set - logical reasoning questions

43.【list的简单属性】

【自校正控制】自校正PID

05 | 后台登录:基于账号密码的登录方式(下)

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

jsArray array copy method performance test 2207292307

shell 编程规范与变量
随机推荐
SyntaxError: EOL while scanning string literal
CF1320E Treeland and Viruses
[VMware virtual machine installation mysql5.7 tutorial]
No-code development platform all application settings introductory tutorial
R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
ENVI Image Processing (6): NDVI and Vegetation Index
CF603E Pastoral Oddities
strlen跟sizeof区别
新一代开源免费的终端工具,太酷了
cpu/CS and IP
(论文翻译]未配对Image-To-Image翻译使用Cycle-Consistent敌对的网络
(HR Interview) Most Common Interview Questions and Skilled Answers
高性能数据访问中间件 OBProxy(三):问题排查和服务运维
Composer安装方式
【Advanced Mathematics】【7】Double Integral
js背景切换时钟js特效代码
Classic test interview questions set - logical reasoning questions
58. 最后一个单词的长度
数据中台建设(五):打破企业数据孤岛和提取数据价值
Synology system installation related file sharing