You are not logged in.
Pages: 1
Hi
i need a script (not a report) to connect to a database table, for using that data.
is there a built in object to obtain an existing datasource?
or have to be made using jdbc and setting the url connection?
kind regards
Offline
Hi unsi_2,
you can access an existing datasource directly via script using the "connection" object, pls take a look here:
https://reportserver.net/en/tutorials/t … scripting/
If you don't create a script report, but you need a plain script, you can use groovy sql's constructs to connect to any database: https://docs.groovy-lang.org/latest/htm … l/Sql.html
or you can use plain JDBC calls too.
You can also get a datasource via DataSource Service: net.datenwerke.rs.core.service.datasourcemanager.DatasourceService.getDatasourceByName(String)
Pls check the services list in the API, available in the sourceforge downloads: https://sourceforge.net/projects/dw-rs/files/
Regards,
Eduardo
Offline
many thanks Eduardo.
yes, it is a plain script, so for accessing a RS datasource i imagine i cannot use groovy sql's constructs, only the objects of the API.
Offline
Hi unsi_2,
you can access RS datasources and also use groovy sql constructs with these.
For example, you can access the query of a given dynamic list with id 1234 by:
import net.datenwerke.rs.base.service.reportengines.table.entities.TableReport;
import net.datenwerke.rs.core.service.reportmanager.ReportService;
/* getQuery from dynamic list */
ReportService reportService = GLOBALS.getRsService(ReportService.class);
TableReport tableReport = reportService.getReportByKey(1234);
String query = tableReport.getDatasourceContainer().getDatasourceConfig().getQuery();
so you can use plain groovy sql constructs with this query.
You can also get a connection of a given datasource MY_DS using the connection pool:
import net.datenwerke.rs.core.service.datasourcemanager.DatasourceService;
import net.datenwerke.rs.base.service.datasources.definitions.DatabaseDatasource;
import net.datenwerke.dbpool.DbPoolService;
import net.datenwerke.dbpool.config.ConnectionPoolConfig;
import java.sql.Connection;
DatasourceService datasourceService = GLOBALS.getRsService(DatasourceService.class);
DbPoolService dbPoolService = GLOBALS.getRsService(DbPoolService.class);
DatabaseDatasource ds = (DatabaseDatasource) datasourceService.getDatasourceByName("MY_DS");
ConnectionPoolConfig config = ds.getConnectionConfig();
Connection conn = dbPoolService.getConnection(config).get();
the connection (conn) can be used with groovy constructs, e.g. you can construct an SQL object using the given connection: https://docs.groovy-lang.org/latest/htm … onnection)
def sql = new Sql(conn)
Regards,
Eduardo
Offline
Pages: 1