package DataBase; import java.sql.*; public class MSDBdemo { public static void main(String[] args){ try{ Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); System.out.PRintln("数据库驱动程序注册成功!"); String url ="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=northwind"; String user = "sa"; String passWord = ""; Connection conn = DriverManager.getConnection(url, user, password); System.out.println("数据库连接成功"); }catch(Exception e){ e.printStackTrace(); System.out.println("数据库连接失败"); } } } |