jdbc连接本机SQL Server数据库

//需要提前导入SQL Server的架包

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Demo1 {
     static final String URL = "jdbc:sqlserver://localhost:1433;databaseName=dbtest";
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
          

        try {
            // Connection conn=DriverManager.getConnection(dbURL,"sa","hct");//需要输入登录用户名和登录密码
            Connection conn = DriverManager.getConnection(URL, "sa", "hct");
            System.out.println(conn);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
 

你可能感兴趣的:(服务器MySQL)