我试图将此功能公开为Web服务,我的功能显示主机中的所有数据库,我收到此错误,我试图连接到microsoft sql server。 不知道我哪里错了。
public List<String> connexion(){
Connection conn = null;
List <String> listdb= new ArrayList<>();
listdb.add("ok");
try {
String dbURL = "jdbc:sqlserver://x.x.x.x\\sqlexpress";
String user = "xxx";
String pass = "xxx";
conn = DriverManager.getConnection(dbURL, user, pass);
if (conn != null) {
DatabaseMetaData dm = (DatabaseMetaData) conn.getMetaData();
System.out.println("Driver name: " + dm.getDriverName());
System.out.println("Driver version: " + dm.getDriverVersion());
System.out.println("Product name: " + dm.getDatabaseProductName());
System.out.println("Product version: " + dm.getDatabaseProductVersion());
ResultSet rs = conn.getMetaData().getCatalogs();
while (rs.next()) {
listdb.add(rs.getString("TABLE_CAT"));
System.out.println("TABLE_CAT = " + rs.getString("TABLE_CAT") );
return listdb;
}
return listdb;
}
} catch (SQLException ex) {
ex.printStackTrace();
}
finally {
try {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException ex) {
ex.printStackTrace();
}
}
return listdb;
}