How eclipse SqlServer database connection

Step One: First open SqlServer
Here Insert Picture Description
Step Two: Import database file
, right-click on the database to select additional
appeared the following interface
Here Insert Picture Description
Next select Add, locate the database files are stored
Here Insert Picture Description
and finally click OK;

If you want to change the sa login password SqlServer
find sa login name in the security file
Here Insert Picture Description
and select properties you can modify your password! ! !

Step Four: Right-click on the project name to select Build Path; then select Add External Archives to find downloaded jdbc driver (not download their own);

Step five: Test if it connects successfully
built a text class

package restful.test;

import java.sql.*;
public class test {
	public static void main(String [] args){
		  String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
		  String dbURL="jdbc:sqlserver://127.0.0.1:1433;DatabaseName=suit";//这里是写你的数据库名字。上面是新建立了Test,所以填Test
		  String userName="sa";//这里是写你的登陆数据库的名,安装完默认是sa
		  String userPwd="zt123456";//这里是写你的登陆数据库的密码,我设定的比较简单
		  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连接失败!");
		  }       
	}
}

If the connection is successful there will be a database connection success! ! !
Here Insert Picture Description

Published 444 original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/zt2650693774/article/details/103204915