就像标题所说的那样。我尝试编写一个教程来展示如何与 ms sql server 进行通信。
我可以与系统数据库如master和model进行通信。但是当我手动创建数据库时,我无法访问数据库。我得到的只是:无法打开请求数据库。
String driverName="com.microsoft.sqlserver.jdbc.SQLServerDriver";
String dbURL = "jdbc:sqlserver://127.0.0.1:1433; DatabaseName=ddf"; //ddf is what I created.
String userName = "sa";
String userPwd = "123456";
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
System.out.println("Connection Successful!");
Statement stmt = dbConn.createStatement();
String sql = "select * from ddf..ff";
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
System.out.println(rs.getRow());
}
rs.close();
stmt.close();
dbConn.close();