ColdFusion - java object method call

后端 未结 3 1589
甜味超标
甜味超标 2021-01-27 02:57

I\'m trying to get a list of datasources off my server (Yes I am the server owner...this is not a hack).

I think I confused the issue by giving two examples - so I\'m e

相关标签:
3条回答
  • 2021-01-27 03:36
    dbserv = createobject("java","coldfusion.server.ServiceFactory").getDatasourceService();
    dblist = dbserv.getDatasources(); 
    writedump(dblist);
    

    This works in ColdFusion. If you are getting securitycredential exception then you need to login as admin like

    admin = new cfide.adminapi.Administrator();
    admin.login("password","admin");
    

    The following code will not work

    dbserv2 = createobject("java","coldfusion.server.DataSourceService");
    dblist2 = dbserv2.getDatasources();
    

    And it is rightfully throwing method not found. Mainly because DataSourceService is a java Interface and doesn't have this method implemented. It is implemented by Executive class.

    0 讨论(0)
  • 2021-01-27 03:46

    For others who may happen upon this post, another way to do what was wanted, without needing to authenticate with the CF Admin password is to use the getNames() function of the DataSourceService instead of getDatasources. It returns an array of all the datasource names registered on the server.

    <cfscript>
        dbserv3 = createobject("java","coldfusion.server.ServiceFactory").getDataSourceService();
        dblist3 = dbserv3.getNames();
    </cfscript>
    

    This works on CF11

    0 讨论(0)
  • 2021-01-27 03:47

    If you dump your dbserv2 variable you will see that it is not an object, it is a Java Interface, which cannot be instantiated.

    To do what you want you need to request the datasource service from the service factory.

    <cfscript>
        dbserv2 = createobject("java","coldfusion.server.ServiceFactory").getDataSourceService();
    
        dblist2 = dbserv2.getDatasources();
    </cfscript>
    
    0 讨论(0)
提交回复
热议问题