Harici Veri Kaynaklarını Alma Ayrıntıları
Contents
[
Hide
]
Bazen, dış veri kaynakları hakkında bilgi almak isteyebilirsiniz. Örneğin, SQL bağlantı verilerini görmek isteyebilirsiniz. Bu bilgiler, bir SQL sunucusuna bağlanmak için gerekli olan her türlü veriyi içerebilir; örneğin, sunucu URL’si, kullanıcı adı, temel alınan tablo adı, SQL sorgusu, sorgu türü, tablonun konumu vb.
Aspose.Cells, şablon Excel dosyalarına bağlı kurumsal veritabanlarından bu tür ayrıntıları almak için bazı yararlı aramalar sağlar.
Harici Veri Kaynaklarını Alma Ayrıntıları
Aşağıdaki örnek, veritabanı bağlantısının ve diğer ayrıntıların nasıl alınacağını gösterir. Örnekte, dış veri kaynağına (SQL Server) bağlantılar içeren basit bir Excel dosyası kullanılmıştır.
Kod çalıştığında, bağlantı detayları konsola yazdırılır.
SQL bağlantı bilgileri
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RetrievingExternalDataSourcesDetails.class); | |
// Open the template Excel file | |
Workbook workbook = new Workbook(dataDir + "connection.xlsx"); | |
// Get the external data connections | |
ExternalConnectionCollection connections = workbook.getDataConnections(); | |
// Get the count of the collection connection | |
int connectionCount = connections.getCount(); | |
// Create an external connection object | |
ExternalConnection connection = null; | |
// Loop through all the connections in the file | |
for (int i = 0; i < connectionCount; i++) { | |
connection = connections.get(i); | |
if (connection instanceof DBConnection) { | |
// Instantiate the DB Connection | |
DBConnection dbConn = (DBConnection) connection; | |
// Print the complete details of the object | |
System.out.println("Command: " + dbConn.getCommand()); | |
System.out.println("Command Type: " + dbConn.getCommandType()); | |
System.out.println("Description: " + dbConn.getConnectionDescription()); | |
System.out.println("Id: " + dbConn.getConnectionId()); | |
System.out.println("Info: " + dbConn.getConnectionInfo()); | |
System.out.println("Credentials: " + dbConn.getCredentials()); | |
System.out.println("Name: " + dbConn.getName()); | |
System.out.println("OdcFile: " + dbConn.getOdcFile()); | |
System.out.println("Source file: " + dbConn.getSourceFile()); | |
System.out.println("Type: " + dbConn.getType()); | |
// Get the parameters collection (if the connection object has) | |
ConnectionParameterCollection parameterCollection = dbConn.getParameters(); | |
// Loop through all the parameters and obtain the details | |
int paramCount = parameterCollection.getCount(); | |
for (int j = 0; j < paramCount; j++) { | |
ConnectionParameter param = parameterCollection.get(j); | |
System.out.println("Cell reference: " + param.getCellReference()); | |
System.out.println("Parameter name: " + param.getName()); | |
System.out.println("Prompt: " + param.getPrompt()); | |
System.out.println("SQL Type: " + param.getSqlType()); | |
System.out.println("Param Type: " + param.getType()); | |
System.out.println("Param Value: " + param.getValue()); | |
} | |
} | |
} |