Difference between revisions of "Documentation/DevGuide/Database/PreparedStatement From DataSource Queries"
From Apache OpenOffice Wiki
< Documentation | DevGuide
OOoWikiBot (Talk | contribs) m (Robot: Changing Category:Documentation/Developers Guide/Database Access) |
OOoWikiBot (Talk | contribs) m (FINAL VERSION FOR L10N) |
||
Line 5: | Line 5: | ||
|NextPage=Documentation/DevGuide/Database/Database Design | |NextPage=Documentation/DevGuide/Database/Database Design | ||
}} | }} | ||
− | {{DISPLAYTITLE:PreparedStatement From DataSource Queries}} | + | {{Documentation/DevGuideLanguages|Documentation/DevGuide/Database/{{SUBPAGENAME}}}} |
+ | {{DISPLAYTITLE:PreparedStatement From DataSource Queries}} | ||
<!--<idltopic>com.sun.star.sdb.XCommandPreparation;com.sun.star.sdb.CommandType</idltopic>--> | <!--<idltopic>com.sun.star.sdb.XCommandPreparation;com.sun.star.sdb.CommandType</idltopic>--> | ||
Use the <idl>com.sun.star.sdb.XCommandPreparation</idl> to get the necessary statement objects to open predefined queries and tables in a data source, and to execute arbitrary SQL statements: | Use the <idl>com.sun.star.sdb.XCommandPreparation</idl> to get the necessary statement objects to open predefined queries and tables in a data source, and to execute arbitrary SQL statements: |
Revision as of 12:50, 15 May 2009
- ResultSetMetaData
- Using Prepared Statements
- PreparedStatement From DataSource Queries
Use the com.sun.star.sdb.XCommandPreparation to get the necessary statement objects to open predefined queries and tables in a data source, and to execute arbitrary SQL statements:
com::sun::star::sdbc::XPreparedStatement prepareCommand( [in] string command, [in] long commandType)
If the value of the parameter com.sun.star.sdb.CommandType is TABLE
or QUERY
, pass a table name or query name that exists in the com.sun.star.sdb.DataSource of the connection. The value COMMAND
makes prepareCommand()
expect an SQL string. The result is a prepared statement object that can be parameterized and executed.
The following fragment opens a predefined query in a database Ada01:
// retrieve the DatabaseContext and get its com.sun.star.container.XNameAccess interface XNameAccess xNameAccess = (XNameAccess)UnoRuntime.queryInterface( XNameAccess.class, _rMSF.createInstance("com.sun.star.sdb.DatabaseContext")); Object dataSource = xNameAccess.getByName("Ada01"); XDataSource xDataSource = (XDataSource)UnoRuntime.queryInterface(XDataSource.class, dataSource); Object interactionHandler = _rMSF.createInstance("com.sun.star.sdb.InteractionHandler"); XInteractionHandler xInteractionHandler = (XInteractionHandler)UnoRuntime.queryInterface( XInteractionHandler.class, interactionHandler); XCompletedConnection xCompletedConnection = (XCompletedConnection)UnoRuntime.queryInterface( XCompletedConnection.class, dataSource); XConnection xConnection = xCompletedConnection.connectWithCompletion(xInteractionHandler); XCommandPreparation xCommandPreparation = (XCommandPreparation)UnoRuntime.queryInterface( XCommandPreparation.class, xConnection); XPreparedStatement xPreparedStatement = xCommandPreparation.prepareCommand( "Query1", CommandType.QUERY); XResultSet xResult = xPreparedStatement.executeQuery(); XRow xRow = (XRow)UnoRuntime.queryInterface(XRow.class, xResult); while (xResult != null && xResult.next()) { System.out.println(xRow.getString(1)); }
Content on this page is licensed under the Public Documentation License (PDL). |