简体   繁体   English

在不使用Servicefactory的情况下获取JDBC数据库连接

[英]Getting a JDBC database connection without using Servicefactory

I'm using the following java code (in ColdFusion) to get a database connection: 我正在使用以下java代码(在ColdFusion中)来获取数据库连接:

//Creating an object of servicefactory class
local.theServiceFactory = createObject('java','coldfusion.server.ServiceFactory');

//Creating the connection object simply by passing the DSN name
local.connect = theServiceFactory.getDataSourceService().getDataSource('dsnnane').getConnection();

Works great. 效果很好。 The only problem is I'm told I can't use ServiceFactory because of security reasons. 唯一的问题是我被告知由于安全原因我不能使用ServiceFactory Is there another way to get the connection object? 有没有其他方法来获取连接对象?

Instead of dropping lower in the call stack to do this kind of thing, I'd look at ways to set your options directly via the SQL itself. 我没有在调用堆栈中降低执行此类操作,而是通过SQL本身直接设置选项。 As I posted in my comment, you can set the autocommit values in SQL Server via T-SQL itself. 正如我在评论中发布的那样,您可以通过T-SQL本身在SQL Server中设置autocommit

I use it like this 我这样用它

var datasourceService = createObject("Java", "coldfusion.server.ServiceFactory").getDataSourceService();
    var ds = datasourceService.getDatasource(variables.dsn).getConnection().getPhysicalConnection();
    ds.setAutoCommit(false);
    ...
    ds.setAutoCommit(true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM