JDBC 连接 SQL数据库的两种方法
1.加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
2.建立连接
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=course;user=sa;password=sasa;");
第二种方法
1.加载驱动
String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url="jdbc:sqlserver://localhost:1433;databaseName=course;";
String user="sa";
String password="sasa";
2.建立连接
Connection conn = DriverManager.getConnection(url,user,password);
具体请参见例子包中的sqlserver1和2.
1.加载驱动
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
2.建立连接
Connection conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=course;user=sa;password=sasa;");
第二种方法
1.加载驱动
String driver="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url="jdbc:sqlserver://localhost:1433;databaseName=course;";
String user="sa";
String password="sasa";
2.建立连接
Connection conn = DriverManager.getConnection(url,user,password);
具体请参见例子包中的sqlserver1和2.
本文介绍了使用JDBC连接SQL Server数据库的两种方法。首先通过加载驱动并指定URL、用户名和密码来创建连接。提供了具体的代码示例,帮助读者快速上手。
998

被折叠的 条评论
为什么被折叠?



