How to generate a query automatically?

Hello,
I set up a PreparedStatment pstmt = conn.prepareStatment(" select distinct ? from table ")
and then
pstmt.setString(1, "country")
and I use ResultSet rs = pstmt.executeQuery()
but the result is not what I expect.. It only returns "country"
if I change it to stmt = conn.createStatement("select distinct country from table")
it works
So, how can I generate a query like this automatically?
Thanks!

The query you posted means "return the first argument once for every row in the table called 'table'." What is it you are trying to do?
And, you may want to post this on the JDBC forum rather than here.

Similar Messages

  • How to generate web.xml automatically?

    Hi all!
    I am new to servlets. I have configured the tomcat 5.5.9 with eclipse 3.0 succussfully. It is generating the class files. But I want to know how to generate web.xml through it.
    Thanks in advance...
    Code Snooker

    AFAIK, there's no template for generating web.xml.
    Navigate to <TomcatInstallDir>/webapps/
    You would find lot of directories - each one being a web application.
    Navigate to any one, say ROOT and then to the WEB-INF directory
    under that.
    You would find a web.xml.
    Copy it into your <web-application-dir>/WEB-INF folder and make necessary changes
    cheers,
    ram.

  • How to generate mdx query using C#

    I am new to mdx query and i am very curious about mdx query generation using c# so i searched for any demo or open source then i found
    Ranet.olap, which is providing what i need. After taking the dlls i tried to incorporate them in my code. I am pasting my full
    console code which should generate mdx query but it's not doing so, Am i doing something wrong.
    using System;
    using System.Collections.Generic;
    using Microsoft.AnalysisServices.AdomdClient;
    using Ranet.Olap.Core.Managers;
    using Ranet.Olap.Core.Metadata;
    using Ranet.Olap.Core.Types;
    namespace MDX
        class Program
            static void Main(string[] args)
                startWork();
            public static void startWork()
                string connString = "Provider=MSOLAP.3; Data Source=localhost;Initial Catalog=AdventureWorkDW2008R2;Integrated Security=SSPI;";
                CubeDef cubes;
                AdomdConnection conn = new AdomdConnection(connString);
                conn.Open();
                cubes = conn.Cubes.Find("AdventureWorkCube");
                Ranet.Olap.Core.Managers.MdxQueryBuilder mdx = new Ranet.Olap.Core.Managers.MdxQueryBuilder();
                mdx.Cube = cubes.Caption;
                List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listColumn = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
                List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listRow = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
                List<Ranet.Olap.Core.Wrappers.AreaItemWrapper> listData = new List<Ranet.Olap.Core.Wrappers.AreaItemWrapper>();
                //Column area
                Dimension dmColumn = cubes.Dimensions.Find("Dim Product");
                Microsoft.AnalysisServices.AdomdClient.Hierarchy hColumn = dmColumn.Hierarchies["English Product Name"];
                //hierarchy properties
                List<PropertyInfo> lPropInfo = new List<PropertyInfo>();
                foreach (var prop in hColumn.Properties)
                    PropertyInfo p = new PropertyInfo();
                    p.Name = prop.Name;
                    p.Value = prop.Value;
                    lPropInfo.Add(p);
                Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIColumn = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
                areaIColumn.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
                areaIColumn.Caption = hColumn.Caption;
                areaIColumn.CustomProperties = lPropInfo;
                listColumn.Add(areaIColumn);
                //Rows Area
                Dimension dmRow = cubes.Dimensions.Find("Due Date");
                Microsoft.AnalysisServices.AdomdClient.Hierarchy hRow = dmRow.Hierarchies["English Month Name"];
                List<PropertyInfo> lRowPropInfo = new List<PropertyInfo>();
                foreach (var prop in hRow.Properties)
                    PropertyInfo p = new PropertyInfo(prop.Name,prop.Value);
                    lRowPropInfo.Add(p);
                Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIRow = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
                areaIRow.AreaItemType = AreaItemWrapperType.Hierarchy_AreaItemWrapper;
                areaIRow.Caption = hRow.Caption;
                areaIRow.CustomProperties = lRowPropInfo;
                listRow.Add(areaIRow);
                //Measure Area or Data Area
                Measure ms = cubes.Measures.Find("Order Quantity");
                Ranet.Olap.Core.Wrappers.AreaItemWrapper areaIData = new Ranet.Olap.Core.Wrappers.AreaItemWrapper();
                areaIData.AreaItemType = AreaItemWrapperType.Measure_AreaItemWrapper;
                areaIData.Caption = ms.Caption;
                List<PropertyInfo> lmpropInfo = new List<PropertyInfo>();
                foreach (var prop in ms.Properties)
                    PropertyInfo p = new PropertyInfo(prop.Name, prop.Value);
                    lmpropInfo.Add(p);
                areaIData.CustomProperties = lmpropInfo;
                listData.Add(areaIData);
                mdx.AreaWrappersColumns = listColumn;
                mdx.AreaWrappersRows = listRow;
                mdx.AreaWrappersData = listData;
                string mdxQuery = mdx.GenerateMdxQuery();
                conn.Close();

    Hi mkm1,
    According to your description, you want to use C# code to generate MDX Query. Right?
    In Analysis Servcies, we just need to use "Microsoft.AnalysisServices.AdomdClient.dll" to open connection to SSAS database and retrieve data from cube. Here are some sample code about executing MDX query using C#.
    Dim objConnection As New AdomdConnection("Data Source=localhost;Initial Catalog=Adventure Works DW 2008;")
    Dim objCommand As New AdomdCommand()
    Dim objDatatable As New DataTable
    Dim strCommand As String
    strCommand = "SELECT [Measures].[Internet Sales Amount] ON COLUMNS, "
    strCommand = strCommand & " [Date].[Calendar].[Calendar Year] ON ROWS"
    strCommand = strCommand & " FROM [Adventure Works]"
    objConnection.Open()
    objCommand.Connection = objConnection
    objCommand.CommandText = strCommand
    Dim objDataAdapter As New AdomdDataAdapter(objCommand)
    objDataAdapter.Fill(objDatatable)
    objConnection.Close()
    Since your code is more related to a third party API, we suggest you post your question to Rnet.
    Reference:
    Microsoft.AnalysisServices.AdomdClient Namespace
    If you have any question, please feel free to ask.
    Simon Hou
    TechNet Community Support

  • How to generat code numbers automatically?

    Dear members,
    i have 3 tables with code no which are primary key and char datatype.
    the first code number is 2 characters,
    then the 2nd code number is 5 characters
    then 3rd code number is 9 characters.
    the first table's code numbers are manually defined. 10, 20, 30 and so on.
    but the requirement is to generate the 2nd table's code number automatically by fixing the 1st tables 2 characters on the left and then 10001, 10002, 10003, 10004 and so on.
    and like this the 3rd table's code number to be generated by fixing the first 5 characters on the left from the 2nd table and the 4 characters on the right 100010001, 100010002, 100010003, 100010004 and so on.
    for example:
    FIRST TABLE 2ND TABLE 3RD TABLE
    10 10001 100010001
    10002 100020001
    20 20001 200010001
    20002 200020001
    30 30001 300010001
    30002 300020001
    How can do this job?
    i issue the following query.
    declare
    v_2nd_code_no char(5);
    begin
    select max(2nd_code)+1 into v_2nd_code_no from 2nd_table;
    select first_code_no||v_2nd_code_no into :blk.item from dual;
    end;
    it give the following error.
    ORA-06502: PL/SQL: numeric or value error string
    now how can i do this job.
    thanks in advance.
    Muhammad Nadeem
    [email protected]

    Muhammed,
    I think you should reconsider your design. Duplicating data into other columns will give you update headaches, uses extra storage, and fool the optimizer, and maybe others will point out more disadvantages.
    In my opinion your table should look like this:
    code1 number(2,0)
    code2 number(3,0)
    code3 number(4,0)
    Please note that they are numbers! Using numbers for numbers is the right way for not fooling the optimizer. Before executing a query, Oracle determines the access path to retrieve all information, based on statistical information on all the tables,columns and indexes involved. If you issue a query with a predicate like:
    code3 between '100019999' and '100020000'the optimizer will think there are numerous strings between the two "numbers" and will maybe head towards a full table scan, or at least think there are thousands of values between the two.
    Now, if in your application you want to get a nicely displayed number with leading zeros and all, you just use:
    rpad(to_char(code1),2,'0') || rpad(to_char(code2),3,'0') || rpad(to_char(code3),4,'0')Regards,
    Rob.

  • How to generate a query involving multiple tables(one left join others)

    Hi, all,
    I want to query a db like these:
    I need all the demographics information(from table demo) and their acr info(from table acr), and their clinical info(from table clinical), and their lab info(from table lab).
    The db is like this:
    demo->acr: one to many
    demo->clinical info: one to many
    demo->lab info: one to many
    I want to get one query result which are demo left join acr, and demo left join clinical, and demo left join lab. I hope the result is a record including demo info, acr info, clinical info, and lab info.
    How could I do this in SQL?
    Thanks a lot!
    Qian

    Thank you very, very much!
    Actually, I need a huge query to include all the tables in our db.
    We are running a clinical db which collects the patients demographics info, clinical info, lab info, and many other information.
    The Demographics table is a center hub which connects other tables. This is the main architecture.
    My boss needed a huge query to include all the information, so others could find what they need by filtering.
    As you have found, because one patients usually has multiple clinical/lab info sets, so the result will be multiplied! the number of result=n*m*k*...
    My first plan is to set time point criteria to narrow all the records with one study year. If somebody needs to compare them, then I have to show them all.
    So I have to know the SQL to generate a huge query including as many tables as possible.
    I show some details here:
    CREATE TABLE "IMMUNODATA"."DEMOGRAPHICS" (
    "SUBJECTID" INTEGER NOT NULL,
    "WORKID" INTEGER,
    "OMRFHISTORYNUMBER" INTEGER,
    "OTHERID" INTEGER,
    "BARCODE" INTEGER,
    "GENDER" VARCHAR2(1),
    "DOB" DATE,
    "RACEAI" INTEGER,
    "RACECAUCASIAN" INTEGER,
    "RACEAA" INTEGER,
    "RACEASIAN" INTEGER,
    "RACEPAC" INTEGER,
    "RACEHIS" INTEGER,
    "RACEOTHER" VARCHAR2(50),
    "SSN" VARCHAR2(11),
    PRIMARY KEY("SUBJECTID") VALIDATE
    CREATE TABLE "IMMUNODATA"."ACR" (
    "ID" INTEGER NOT NULL,
    "THEDATE" DATE ,
    "SUBJECTID" INTEGER NOT NULL,
    "ACR_PAGENOTCOMPLETED" VARCHAR2(1000) ,
    "ACR_MALARRASHTODAY" INTEGER ,
    "ACR_MALARRASHEVER" INTEGER ,
    "ACR_MALARRSHEARLIESTDATE" DATE ,
    PRIMARY KEY("ID") VALIDATE,
    FOREIGN KEY("SUBJECTID") REFERENCES "IMMUNODATA"."DEMOGRAPHICS" ("SUBJECTID") VALIDATE
    CREATE TABLE "IMMUNODATA"."CLIN" (
    "ID" INTEGER NOT NULL,
    "THEDATE" DATE ,
    "SUBJECTID" INTEGER NOT NULL,
    "CLIN_PAGENOTCOMPLETED" VARCHAR2(1000) ,
    "CLIN_FATIGUE" VARCHAR2(20) ,
    "CLIN_FATIGUEDATE" DATE ,
    "CLIN_FEVER" VARCHAR2(20) ,
    "CLIN_FEVERDATE" DATE ,
    "CLIN_WEIGHTLOSS" VARCHAR2(20) ,
    "CLIN_WEIGHTLOSSDATE" DATE ,
    "CLIN_CARDIOMEGALY" VARCHAR2(20) ,
    PRIMARY KEY("ID") VALIDATE,
    FOREIGN KEY("SUBJECTID") REFERENCES "IMMUNODATA"."DEMOGRAPHICS" ("SUBJECTID") VALIDATE
    Other tables are alike.
    Thank very much!
    Qian

  • How to generate customer invoices automatically?

    We are doing direct debit for some of our clients based on the billing plan. 
    I know that it is possible to create customer invoices automatically based on the billing plan, but do not know the details how to trigger the process.
    Imagine I have created the billing plan for the billing WBS-element.  What should be done next to post the customer invoice automatically?
    Many thanks for your help!

    Hi Mrinal,
    I do not know much about SD process, in fact I am mostly interested in FI invoices to be generated and posted while having the most dummy SD flow possible.
    What exactly does VF04, what are prerequisites to run it, and what are the follow up steps?  My starting point is the billing plan maintained for the WBS-element, while the target is FI customer invoices posted, so what are the missing steps in between?
    Many thanks.

  • How to generate item codes automatically

    Hi,
    My customer wants that the inventory item code be generated automatically based on its description. The code should have:
    - 3 first characters of the description
    - A sequential increased number, to make the code unique.
    e.g. the item called "Petrol" should have the code "pet004".
    To achieve this, I have created a database procedure. So the user that works in "Item Master" form, will fill out "description" field and the "Item" field should be automatically populated based on the return value of this procedure.
    Is there any way how to achieve this through personalization?
    Or, is there any standard way that Oracle offers for automatic generation of item codes?
    Thank youl

    Hi,
    You have to do it using forms personalization.
    Thanks,
    PS.

  • How to generate a class automatically in JDev

    Suppose from OS side, I create a new empty Java file in the src directory of a project in JDev. Then in JDev, I click on the "refresh"/reload button for that project. Now I see the new java file. Double click it to open it; it is blank. In this case, how can I generate a class using the file name as the class name, and a default constructor or even a main method etc.?
    Is there any convenient way of doing this, rather than going to the usual route, which is File menu, then new, java file, from that UI to give a class name, choose to include a main method etc..
    Thank you.

    Duncan Mills blogged about how to build your own templates http://blogs.oracle.com/groundside/entry/adventures_in_adf_logging_part1
    Not exactly your case, but you should get the idea.
    Timo

  • How to generate swf file automatically on server ?

    Hi. I'm new to flash and i've just learnt how to use OSMF to build a flash player. My question is very basic and i hope to put it as clearly as i can:-
    Now i can create a flash player from flash builder. But in order to point to a new location for the video, i need to recreate the swf from flash builder. So how would i generate a new swf or change the video address on the server when a user uploads a new video. Of course i can't afford to build the project in flash builder myself every time a video is uploaded !
    I think the answer incldes flex, that's why i'm asking here. Thank you.

    For what you're using it for, it sounds like you would do better to create one SWF that can have different data fed into it, either by loading external data such as XML, or by using application paramters (flashVars). Use this data to determine the correct location of the video.
    However, it is possible to compile server side using the mxmlc and/or compc compiler. For example, I use Apache Ant to compile themes on the server-side, which then get loaded into an app at runtime. IMHO, this method should only be used for compiling "resources," and not used for compiling "information," as your post suggests.

  • How to generate Attribute Sets Automatically?

    it show in Oracle Application Framework Developer’s Guide Release 12.1.2 December 2009 as follow:
    /jdevbin/<SelectedJDevBuild>/build attributesets APPS APPS
    appsdbs.us.oracle.com 1521 devdb /home/jfrost/jdevhome/jdev/myprojects PO
    What is build? how to get it? or How to get Attribute Set Generator?
    Edited by: Kevin on 2010/12/7 下午 6:57

    AFAIK, there's no template for generating web.xml.
    Navigate to <TomcatInstallDir>/webapps/
    You would find lot of directories - each one being a web application.
    Navigate to any one, say ROOT and then to the WEB-INF directory
    under that.
    You would find a web.xml.
    Copy it into your <web-application-dir>/WEB-INF folder and make necessary changes
    cheers,
    ram.

  • How to generate BSP application automatically

    Hi, BW experts,
        I get some web interfact from transport, for example: Z1, Z2. I failed to run them on the web, then I check the BSP application in SE80 are not generated.
        I use BPS_WB to generate the web interface, selected "save customizing", "Generate BSP Application (Again)" and "Generate Class (Again)".
        then I got the log with green color said "Activity terminated"  , I go to check BSP application but it still not generated.
    anyone can help ?
    Regards

    Jie Miao,
    Which version of BPS are you on?  I worked through an similar issue last week on SEM-BPS 6.0 on NW04S where introduction of a new authorization object S_ICF_ADM gave me false positive on generate and we had issues also with transports even thought no error since the transport id did not have that new object.  This client had security locked down pretty tight.

  • How to generate username automatically while user creation in OIM.

    Hi all,
    Could you please send me steps for how to generate user name automatically by using adapter while creating the user in OIM.

    Follow this link:
    [http://download.oracle.com/docs/cd/B32479_01/doc.903/b32457/creadp.htm|http://download.oracle.com/docs/cd/B32479_01/doc.903/b32457/creadp.htm]
    It will help you to make each adapter which you want but for this you'll have to create entity adapter.

  • Generate  primary key automatically

    Hi, I'd like to know how to generate primary keys automatically with JHeadStart because when I try to make an insert into a table, the page gives me the option of insert the primary key of the register.
    Thanks a lot

    I have a table which have 2 fields, one of those is the primary key, the other is the description.
    I have established the primary key as a DBSequence, but when I try to insert a new record testing the service, appears a negative number in the primary key and instead of that I want to appear the correspondent key, or if doesn't appear the correct value, the insert be done correctly.
    At least I change manually the value if this key, the insert can't be done.

  • How to generate a dynamic update query to update error flag in a mapping?

    i have a mapping in which i m loading log table through generated parameter file.But i want to update the error flag using dynamic update query.for that i have to generate a query and use update sqloverridw in target instances.but i m not getting how to implement it.Please help..!!

    Hi  All, I have a scenario. Below is the source record. field1|field2|field3|field4|field5|field6|field7
    5|20150329|1|980100001|500|My name is Lalita|25
    5|20150329|1|303444442|200|My name is |Lalita.I work in TCS|26
    5|20150329|1|442101001|1000|My name is Lalita.I worked Syntel|56
    5|20150329|1|446788900|300|My name|67  My source file is | separator. But for field6 the data might come with '|'.
    So I want to import the data along with '|' after separating all field in Informatica Layer.  Source team is not going to preformat the file. Please suggest how to achive this.

  • How to generate a View from Query

    Hi
    How to save a Query as a view....that to be used in web templates
    I had a query with 20 diff columns and 20 free chars in it.
    My requirment is to generate 5 to 8 different views for the same query with diff combinations KF's & CHAR's and same them and then assign then to users according to their requirment
    That will make easy to maintain the Query
    Thanks

    Hi,
    1) Execute the query in BEx analyser and set/Define the report as you want.
    2) In BEx tool bar click SAVE AS Views and save it.
    3) This view can be used in WAD.
    The Problem with the View is that, whenever there is change in the query, you must regenerate the view.
    Regards,
    Kams

Maybe you are looking for

  • How much data does forwarding use?

    Hi All, Just curious if people know how much data forwarding uses? I'm traveling to Europe next week and need to have my phone available until I meet someone, but then I want to forward it to my home number for the rest of the trip. I know forwarding

  • Include Stock transfer in MRP

    Hello Solution Management, Currently MRP Only check the quantity available for a given  item in the warehouse(s) and suggests to buy/produce it. However it could happen that the stock which need to be used is available in a different warehouse than t

  • Help! people cant view site

    Hi, I made a site using iWeb a couple months ago and everything was fine. Last week I updated the site and announced it to a bunch of friends and about 80% could not get in or view the site. Most are on a pc, but some still were able to view it ok ev

  • Muse 2014.1.1.6 Freezes on Save and Re-Opening Document

    I was editing and removing Paragraph Styles. Then I edited text with "local" styling (bolded and italicized type -- didn't see the need make a Character Style for that). I did a "Save." Then it freezes, will not close or quit. Force Quit necessary. A

  • PHOTOSHOP ELEMENTS 7 AND CANON ZOOMBROWSER

    I have just bought elements 7 and wish to import all my photos with their keyword tags into elements, but the keywords do not seem to transfer. Please can anyone help?