当前位置:网站首页>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
边栏推荐
猜你喜欢

如何判断自己是否适合IT行业?方法很简单

ENVI图像处理(6):NDVI和植被指数

Flask框架——Flask-Mail邮件

LeetCode二叉树系列——515.最每个树行中找最大值

时间序列的数据分析(四):STL分解

LeetCode二叉树系列——144.二叉树的最小深度

05 | login background: based on the password login mode (below)

以unity3d为例解读:游戏数据加密

Self-tuning PID self-tuning control 】 【
![[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)](/img/65/7bd87794ebde510ecfd1b0e4bd4c94.png)
[Advanced ROS] Lecture 11 Robot co-simulation based on Gazebo and Rviz (motion control and sensors)
随机推荐
LeetCode二叉树系列——116.填充每个节点的下一个右侧指针
libudev 使用说明书
jsArray array copy method performance test 2207300823
TaskDispatcher source code parsing
AT4108 [ARC094D] Normalization
【自校正控制】自校正PID
ENVI Image Processing (6): NDVI and Vegetation Index
CF603E Pastoral Oddities
“封号斗罗” 程序员修炼之道:通向务实的最高境界
pytorch学习记录(六):循环神经网络 RNN & LSTM
网络安全——lcx的使用
el-table中el-table-column下的操作切换class样式
LeetCode二叉树系列——107.二叉树的层序遍历II
数据中台建设(五):打破企业数据孤岛和提取数据价值
CF1320E Treeland and Viruses
权威推荐!腾讯安全DDoS边缘安全产品获国际研究机构Omdia认可
12、 学习MySQL 排序
【软考软件评测师】自动化测试章节下篇
CF338E Optimize!
OFDM Sixteen Lectures 3- OFDM Waveforms