Step One: First open SqlServer
Step Two: Import database file
, right-click on the database to select additional
appeared the following interface
Next select Add, locate the database files are stored
and finally click OK;
If you want to change the sa login password SqlServer
find sa login name in the security file
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! ! !