import java.sql.*; /** * java 连接sqlserver数据库语句 * @author Administrator * */ public class Main { public static void main(String [] args) throws SQLException { String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver"; //加载驱动 String dbURL="jdbc:sqlserver://localhost:1433;DatabaseName=Test"; //地址及数据库名称 //登录用户名和密码 String userName="sa"; String userPwd="123"; try { Class.forName(driverName); Connection dbConn=DriverManager.getConnection(dbURL,userName,userPwd); System.out.println("连接数据库成功"); } catch(Exception e) { System.out.print("连接失败"); e.printStackTrace(); } } }
转载于:https://www.cnblogs.com/daidai-99/p/4227617.html
