interactive login
non-interactive login
How can I create a connection through a data source, which is registered in the DatabaseContext?
/* get the service manager */
xContext = UNO.connect()
XMcf = xContext~getServiceManager
/* retrieve the DatabaseContext and get its XNameAccess interface */
xNameAccess = xMcf~createInstanceWithContext(-
"{%see com.sun.star.sdb.DatabaseContext}", xContext)~{%see com.sun.star.container.XNameAccess%XNameAccess}
/* we use the mysql-test data sorce */
dataSource = xNameAccess~getByName("mysql-test")
/************ interactive login ************/
/* create an InteractionHandler and get its XInteractionHandler interface */
interactionHandler = XMcf~createInstanceWithContext(-
"{%see com.sun.star.sdb.InteractionHandler}", xContext);
xInteractionHandler = interactionHandler~{%see com.sun.star.task.XInteractionHandler%XInteractionHandler}
/* query for the XCompletedConnection interface of the data source */
xCompletedConnection = dataSource~{%see com.sun.star.sdb.XCompletedConnection%XCompletedConnection}
/* connect with interactive login */
xConnection = xCompletedConnection~connectWithCompletion(xInteractionHandler);
/************ non-interactive login ************/
/*
/* query for the XDataSource interface of the data source */
xDataSource = dataSource~{%see com.sun.star.sdbc.XDataSource%XDataSource}
/* simple way to connect - hard code (usr,pw) */
xConnection = xDataSource~getConnection("stefan","apple");
*/
say "Connection created!"
/* get the XClosable interface and close the connection */
xConnection~{%see com.sun.star.sdbc.XCloseable%XCloseable}~close
say "Connection closed!"
::requires UNO.cls -- get UNO support