public Connection getConnection(){ Connection conn=null; try { //加载数据库驱动 Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); System.out.println("数据库驱动加载成功!!"); //定义连接数据库的url String url="jdbc:sqlserver://localhost:1433;DatabaseName=db_database22"; //定义连接数据库的用户名 String userName="sa"; //定义连接数据库的密码 String passWord=""; conn=DriverManager.getConnection(url,userName,passWord); System.out.println("已成功地与SQLServer数据库建立连接!!"); } catch (ClassNotFoundException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return conn; }
【SQLServer】JDBC连接SQLServer数据库
猜你喜欢
转载自blog.csdn.net/hutuyaoniexi/article/details/80630781
今日推荐
周排行