How to get SQL statement from (Collection) query.execute();

We have a JDO Persistence class ClassName that execute query using following code. After this statement get executed, record does not get updated in the DB. Is there a way to check what SQL statement got submitted in the (Collection) query.execute(); ??? <br><br>
Extent extent = pm.getExtent(ClassName.class, false); <br>
Query query = null; <br>
try { <br>
query = pm.newQuery(extent, filter); <br>
Collection results = (Collection) query.execute();<br>
Iterator i = results.iterator();<br>
if (i.hasNext()) {<br>
...<br>
}<br>

You can always find out the names of tables that are views, using java.sql.DatabaseMetaData and its getTables() method.
This tends to be a nice source of examples:
javaalmanac.com
However, if you're asking for the underlying SQL used to CREATE VIEW, I don't see anything in the API that will give you that. After all, JDBC shouldn't have to know if it's dealing with an ordinary table or a view. I think you'd have to ask your DBA for the underlying SQL.
Once you have it, what do you plan to do with it?
%

Similar Messages

  • BusinessObject 4.0 API to get SQL statement from webi or crystal report

    Hello,
    Need your help.... could you confirm whether BusinessObjects 4.0 provides any SDK, API or Web Service to get physical SQL statement from the webi or crystal reports file?
    If so, could you provide name of package, class and method?
    If I am not wrong, there is an SDK in v3.0 that allows to extract the SQL. But I am reading a lot on these forums that lot of SDK classes and functions are deprecated / removed in v4.0.
    Thanks for your help.
    Omer

    For Crystal Reports in BI 4.0 to retrieve the SQL query you can use Report Application Server SDK. Here is a code snippet that retrieves the SQL statement.
    //oInfoObjectReport is of type IInfoObject corresponding to the crystal report.
    ReportClientDocument reportClientDoc = reportAppFactory.openDocument(oInfoObjectReport, 0, Locale.ENGLISH);
            //for all crystal reports
            GroupPath grpPath = new GroupPath();
            //get CR SQL query string
            String reportSQL=reportClientDoc.getRowsetController().getSQLStatement(grpPath,null);
            System.out.println("report SQL String: "+reportSQL);
            //for report whose datasource is command object:
            Tables tables = reportClientDoc.getDatabaseController().getDatabase().getTables();
            for (int i = 0; i < tables.size(); i++)
             ITable table = tables.getTable(i);
             ICommandTable ic= (ICommandTable) table;
             //Command can be obtained from the report using getCommandObject() method
             //get CR SQL query string
             String SQLText=ic.getCommandText();
             System.out.println("SQLText_"+i+": "+SQLText);
    Here are useful links for BI 4.0
    [RAS API Specification|http://help.sap.com/businessobject/product_guides/boexir4/en/xi4_rasjava_apiRef_en.zip]
    [RAS Developer Guide|http://help.sap.com/businessobject/product_guides/boexir4/en/xi4_rasjava_dg_en.zip]

  • Getting SQL statement from OCIStmt

    Is there a way to retrieve the SQL statement from OCIStmt structure? That is, does anyone know what this structure is? For example, if used OCIPrepareStmt, then bound all the variables to OCIStmt, can I tell from OCIStmt what the final SQL statement is? What about the statement string that was originally passed to OCIPrepareStmt()?
    Thanks!
    Igor

    Hey! Thanks for your time!
    use preparedStatements.I'm trying that
    Then use a wrapper class called
    [url=http://www.javaworld.com/javaworld/jw-01-2002/jw-0
    25-overpower.html]debuggableStatement. You willget the SQL that the driver is using.
    Is that only for Debugging or can i use that in live code?
    Thanks again,
    Ryan

  • How to get SQL text from dbms_sql cursor ID

    Hello,
    I have a progam using dbms_sql. A cursor is built by dbms_sql.parse (cur_id, v_query, dbms_sql.native);From now on I have only the internal ID cur_id of the cursor. Is there a way to get back the original query the cursor is built from when the cursor is passed to another package?
    Regards
    Marcus

    Oracle provides several views that show part or all of the SQL statement. See your Oracle version# Reference manual for v$sql...
    v$sqltext is one view that displays the full text but the text is contained in multiple rows.
    HTH -- Mark D Powell --

  • Sql statement from abap query

    is there any chance to get the sql statement (not program) from any abap query created via SQ01?
    I can get the code of program that generated by system, but I cannot get pure sql statement.
    any answer will be appreciated

    I see no parameters, and in the abstract that SQL ought to work.
    However, I halfway suspect that either User, Users, Password, or pass is a reserved word and somebody is getting confused. Try renaming your columns and table...

  • JSF: How to get 2 columns from collection?

    Using datatable i couldn't display 2 colums from collection. In JSF sun implementation is there any way to get?
    my requriement is i need to display collection in matrix format 2*x

    you can use ArrayDataModel object returned to the JSF page inoder to display multiple columes....

  • How to get SQL statements into SE16

    Does anyone know if there is a way in SE16 to get several records for a single Objid?  I do not know the objid but I do know the objid has two records with one having a field1 value of 0001 and the other 0002.  I want to return both records
    This is what the SQL would look like but I'm not sure how I would do in SE16?
    Select * from hrp5122
    where posting_channel = 0001
    and    posting_channel = 0002
    Thanks!

    In the selection screen of SE16, click on the icon on the most right at line POSTING_CHANNEL. You can enter multiple values, ranges and also exclude single entries there.
    Florian

  • How to get MDX code from Smartview query

    Hello everybody:
    I would like to know how to obtain the MDX code when I am performing a query from Smartview. How can I find out what sentence the Provider Service sends to Essbase when doing any operation in Smartview?
    Thank you
    Regards
    Javier

    you might want to use the HypQueryMembers vba call with it you can query the outline directly for a lot of things including User defined attributes
    Here is the code sample from the VBA reference (it is available in Excel by going to the add-ins menu and selecting Hyperion Help
    Description
    HypQueryMembers() executes the member selection query.
    Syntax
    HypQueryMembers (vtSheetName, vtMemberName, vtPredicate, vtOption, vtDimensionName, vtInput1, vtInput2, vtMemberArray)
    ByVal vtSheetName As Variant
    ByVal vtMemberName As Variant
    ByVal vtPredicate As Variant
    ByVal vtOption As Variant
    ByVal vtDimensionName As Variant
    ByVal vtInput1 As Variant
    ByVal vtInput2 As Variant
    ByRef vtMemberArray As Variant
    Parameters
    vtSheetName: (string) Text name of worksheet to operate on. vtSheetName is of the form "[Book.xls]Sheet". If vtSheetName is null, empty, or invalid (nonexistent or name does not match exactly), the active sheet is used.
    vtMemberName: (string) The member name on which to perform the query.
    vtPredicate: (integer) Member selection criteria:
    1 HYP_CHILDREN
    2 HYP_DESCENDANTS
    3 HYP_BOTTOMLEVEL
    4 HYP_SIBLINGS
    5 HYP_SAMELEVEL
    6 HYP_SAMEGENERATION
    7 HYP_PARENT
    8 HYP_DIMENSION
    9 HYP_NAMEDGENERATION
    10 HYP_NAMEDLEVEL
    11 HYP_SEARCH
    12 HYP_WILDSEARCH
    13 HYP_USERATTRIBUTE
    14 HYP_ANCESTORS
    15 HYP_DTSMEMBER
    16 HYP_DIMUSERATTRIBUTES
    vtOption: (integer) Options are dependent on the predicate:
    For the predicate values, HYP_SEARCH and HYP_WILDSEARCH, specify query options: HYP_MEMBERSONLY
    HYP_ALIASESONLY
    HYP_MEMBERSANDALIASES
    vtDimensionName: (string) Dimension to limit the scope of the query. It is used with the following query options and ignored otherwise: HYP_NAMEDGENERATION, HYP_NAMEDLEVEL, HYP_USERATTRIBUTE HYP_SEARCH (set to Null to search through all dimensions), HYP_WILDSEARCH (set to Null to search through all dimensions).
    vtInput1: (string) Input string that is determined by the option. It is used with the following query options and ignored otherwise:
    HYP_NAMEDGENERATION (The name of the generation)
    HYP_NAMEDLEVEL (The name of the level)
    HYP_SEARCH (The string to search for. The string is defined as an exact)
    HYP_WILDSEARCH (The string to search for. The string is defined as an exact search string with an optional '*' at the end to mean any set of characters)
    HYP_USERATTRIBUTE (The user-defined attribute)
    vtInput2: (string) Input string that is determined by the option. It is used with the following query options and ignored otherwise:
    HYP_USERATTRIBUTE (The user-defined attribute)
    HYP_SEARCH, HYP_WILDSEARCH (If the options are set to search in the alias tables, this string specifies which alias table to search. If the string is Null, all alias tables will be searched).
    vtMemberArray: Output that contains the result of the query. If unsuccessful, its contents are unknown.
    Return Value
    Returns a zero if successful; otherwise, returns the appropriate error code.
    Example
    Declare Function HypQueryMembers Lib "HsAddin.dll" (ByVal vtSheetName As Variant, ByVal vtMemberName As Variant, ByVal vtPredicate As Variant, ByVal vtOption As Variant, ByVal vtDimensionName As Variant, ByVal vtInput1 As Variant, ByVal vtInput2 As Variant, ByRef vtMemberArray As Variant) As Long
    Sub QueryMembersEmptyValues()
    vtRet = HypQueryMembers(Empty, Null, HYP_WILDSEARCH,
         HYP_MEMBERSONLY, "Year", "J*", "", vt)
    If IsArray(vt) Then
    cbItems = UBound(vt) + 1
         MsgBox ("Number of elements = " + Str(cbItems))
    For i = 0 To UBound(vt)
         MsgBox ("Member = " + vt(i))
    Next
    Else
    MsgBox ("Return Value = " + Str(vt))
    End If
    End Sub

  • How to send a Mail from a Query executed in a BatchJob ?

    Hi All,
    at Valorec we use SAP ECC 6.0 (EHP 4) and have created some Query's. When executing a Query via the GUI you have the possibility to send the result to a Mail account. (List -> Send to -> E-Mail).
    I would like to start a query in a Batch-Job but sending the generated list to one or more Mail accounts. I hope (and believe) this function is possible but I do not know how.
    Thank you for your support.
    John

    You need to write some ABAP in your Infoset.
    Check the SCN/SDN for "spool email" and you find a lot of thread about this.

  • Exec SQL statement from BW to MS SQL

    Hi Experts,
    I need to execute sql statement from BW on MS SQL Server.
    I want to do it in process chain. There is a so called ABAP Program Component.
    How to implement such a program or function module that will execute on MS SQL Server an sql statement such as for instance:
    "Create view SOME_VIEW as select * from XTABLE".
    I have already configured database connection using DBCO transaction.
    Waiting for response.
    Krzysztof

    Thanks, but that is not what I was asking for.
    I just need to send some SQL statement from BW to MS SQL Server using ABAP program (exec sql or something like this).
    Could you provide me a pattern of such an ABAP program?
    The sql statement is not importent here, I have already extracted data from MS SQL to BW, I have configured dataflow, process chains and so on.
    No I need to determine DELTA on MS SQL Server. I've got some ideas but I need to know how to send SQL statement from BW to MS SQL Server using ABAP program.
    Please any help will be appreciated

  • How to store data into database by reading sql statements from text file

    how to write java program for storing data into database by reading sql statements from text file

    Step 1: Create a property file to add various queries.
    Step 2: Read the properties file using ResourceBundle
    Step 3: Use the jdbc to execute the query read from the property file.
    So in future if you need to change query no need do any modifications in java program. But depends on how you use the property file.

  • How could I investigate SQL statement from standard audit record ?

    We use Oracle 11gR2.
    We use standard audit , audit_trail=DB.
    We found suspicious audit record but that  SQL_BIND,SQL_TEXT colums were NULL.
    How could I investigate that SQL statement from standard audit record ?

    Only "DB, EXTENDED" would cause the SQL statement to be captured.
    If you have the Diagnostics Pack licence you could try querying DBA_HIST_SQLTEXT (joined to DBA_HIST_SNAPSHOT) -- but this would only list SQLs captured by AWR (i.e. the "Top 'N'" SQLs in that snapshot).
    Hemant K Chitale

  • How could I extract past executed SQL statement from dictionary ?

    We use oracle11gR2 on win2008R2.
    How could I extract the past executed SQL statement from dictionary ? (Is it possible from V$SQLTEXT or other dictionary table ?)

    IvicaArsov wrote:
    Hi,
    You can find executed SQL in V$SQLAREA view (if it's still in memory). If it does'n't exist and you have AWR enabled you can query DBA_HIST_SQLTEXT table, but remember that the statistic information in AWR tables is filtered (1 out of 10).
    I.Arsov
    As you know when taking snapshot oracle will capture only top sql statements and stored in AWR.
    But can you please link(source) dba_hist_sqltext contain only 1 out of 10 filtered data?. In dba_hist_active_sess_history yes it contain 1 out of 10 sampled data.

  • How Can I Retrieve SQL Statement From The User ?

    Hi
    I want to know, how can I make the user can enter the SQL statement from himself ?? in this code he can't enter it. Only he can display the SQL that i wrote it...
    this is my Code:
    import java.sql.*;
    public class db_testing {
         static final String DRIVER = "com.mysql.jdbc.Driver";            
         static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
         public static void main(String[] args) {
              Connection cn=null;
              Statement st= null;
              ResultSet rset=null;
              try{
                   Class.forName(DRIVER);
                   cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
                   st=cn.createStatement();
                   rset=st.executeQuery("select * from employee");
                   ResultSetMetaData metadata=rset.getMetaData();
                   System.out.println("The begining: ");
                   for(int i=1;i<=metadata.getColumnCount();i++)
                   System.out.print(metadata.getColumnName(i)+"\t");
                   System.out.println();
                   System.out.println();
                   while(rset.next()){
                   for(int i=1;i<=metadata.getColumnCount();i++)
                   System.out.print(rset.getObject(i)+"\t\t");
                   System.out.println();}
              catch(Exception e){
                   e.printStackTrace();
              finally{
                   try{
                   cn.close();
                   st.close();
                   rset.close();
                   catch(Exception e1){
                        e1.printStackTrace();
    }

    The following changes in the code will make the user to give the input
    import java.sql.*;
    public class db_testing {
    static final String DRIVER = "com.mysql.jdbc.Driver";
    static final String DATABASE_URL = "jdbc:mysql://localhost/S204111933";
    public static void main(String[] args) {
    Connection cn=null;
    Statement st= null;
    ResultSet rset=null;
    try{
    Class.forName(DRIVER);
    cn=DriverManager.getConnection(DATABASE_URL, "root", "admin");
    // st=cn.createStatement();
    // rset=st.executeQuery("select * from employee");
    PreparedStatement pstmt=null;
    pstmt=cn.prepareStatement("select * from employee where id=?");
    pstmt.setInt(1,Integer.parseInt(args[0]));
    rset=pstmt.executeQuery();
    ResultSetMetaData metadata=rset.getMetaData();
    System.out.println("The begining: ");
    for(int i=1;i<=metadata.getColumnCount();i++)
    System.out.print(metadata.getColumnName(i)+"\t");
    System.out.println();
    System.out.println();
    while(rset.next()){
    for(int i=1;i<=metadata.getColumnCount();i++)
    System.out.print(rset.getObject(i)+"\t\t");
    System.out.println();}
    catch(Exception e){
    e.printStackTrace();
    finally{
    try{
    cn.close();
    st.close();
    rset.close();
    catch(Exception e1){
    e1.printStackTrace();
    }

  • How to isolate the Sql Statement from Java Code

    Hi
    I Need to know that can we segregate the Sql Statements and convert them to Stored Procedures so as to isolate the Sql statements from Java Code.
    So i have one static web page which uses four select Statements so what i want is to create a stored procedure encapsulating these queries. So that the Java Web Developer will simply call the Stored Procedure instead of using four different SQL Statements.
    Suppose the developer has these four Statements
    Select ename,empno,sal,job from emp;
    select empno,ename,mgr from emp;
    select deptno,dname from dept;
    select emp.ename,emp.empno,emp.deptno,dept,dname fromemp,dept;
    So can i encapsulate these four Sql Statements in one Procedure and the Web developer can call the Store procedure and dont need to write the Sql Statements in his code.
    Can Anybody guide me how to write this Stored type of Store procedure.
    Thanks

    http://www.google.com/search?q=java+windows+registry
    Next time, search yourself. It might be beyond your belief, but you're really, really not the first person to wonder about this.

Maybe you are looking for