JComboBox contents from a SQL query

Hi
What I'm trying to do is to retrieve 2 fields from a table in my database into a String[] which is then put into a vector. This vector is then passed to a JComboBox. The problem is that when I do this the contents of the JComboBox is gobbly-goop. I think its displaying the address of the string data in memory rather than the data itself. If I only retrieve one coloumn (i.e column 1) from the table into the vector it displays fine.
Any ideas, suggestions will be appreciated.
Thanks

Heres a code snippet of what Im triing to do. Hopefully it will give people a better idea of what Im trying to achieve.
          try
               Statement stufind = con.createStatement();
               String lookup = "SELECT * FROM Student WHERE Techset = '" grpid "'";
               ResultSet rs = stufind.executeQuery(lookup);
               while(rs.next())
                    String[] record = new String[2];
                    record[0] = rs.getString(2);
                    record[1] = rs.getString(3);
                    students.addElement(record);
                    //students.addElement(rs.getString("StudentID"));
               stufind.close();
          catch(SQLException sqlex)
          student = new JComboBox(students);

Similar Messages

  • Get Number of rows from a sql query.

    I am reading data from a sql query in a BLS transaction and I would like to know the number of rows returned.
    Is there an easy way to do this without looping through the table?
    Thanks Jasper

    Hi Jasper,
    You can use the XPATH count function similar to  this:
    GetTagList.Results{count(/Rowsets/Rowset/Row)}
    Kind Regards,
    Diana Hoppe

  • Retreiving a value from and SQL query

    If anyone can give me sample code or pointers to retreive a value from an sql query, I'd be greatful.
    Source code I've muddled together so far:
    Class seqNumType = Class.forName(nameOfClass);
    Constructor theConstructor = seqNumType.getConstructor(null);
    Object seqNumInstance = theConstructor.newInstance(null);
    String theStatement = "SELECT value INTO v_seqnum FROM DUAL;";
    OracleCallableStatement ocs = (OracleCallableStatement)conn.prepareCall(theStatement);
    ocs.registerOutParameter( 1, OracleTypes.NUMBER, 0);
    Method method = seqNumInstance.getClass().getMethod("getORADataFactory", null);
    seqNumInstance = ocs.getORAData(1, (ORADataFactory)method.invoke(null,null));
    ocs.execute();
    Problem with this seems to be the ORADataFactory isn't a method of the class, but as I'm thumbling around in the dark here a little, I've no idea where to go from here. Is this just generally overkill anyway?
    Suggestions?
    Cheers for any help.

    Like this:
                ResultSet resultSet=statement.executeQuery("SELECT * FROM TEST");
                while(resultSet.next())
                    for(int i=0;i<resultSet.getMetaData().getColumnCount();i++)
                        System.out.print(resultSet.getObject(i+1).toString()+" ");
                    System.out.println();

  • Re: How to converting from PL/SQL query to T-SQL query

    How to converting from PL/SQL query to T-SQL query... Its Urgent

    Download the
    SQL Server Migration Assistant for Oracle.  It will convert whole Oracle databases, or single queries or PL/SQL stored procedures.
    With caution that If your database is using Collation which is case sensitive SSMA will not work.SSMA doesnt guarantees 100% for conversion of Queries/stored proc /database if it fails to do so for some queries you will have to do it manually.
    But you can try
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

  • Last Result from Fulltext SQL Query Search Not Showing

    I am creating a custom search results page for MOSS 2007 (using inline .aspx code - don't ask) that uses Fulltext SQL Queries.  I get the results in a ResultTable (see code below) and then use a DataTable to write code to display it (I could have used
    a DataGrid, I know).
    The problem is that the last result is not showing. So, if it reports that there are 5 results, only 4 will show. I have verified that all 5 results do exist (using a slightly broadened query). If it reports 1 result, none exist in the DataTable that loads
    the result data from the ResultTable.
    FullTextSqlQuery query = new FullTextSqlQuery(site);
    query.ResultTypes = ResultType.RelevantResults;
    query.QueryText = qry;
    query.RowLimit = 50;
    query.StartRow = iPage;
    try
    ResultTableCollection results = query.Execute();
    ResultTable resultTable = results[ResultType.RelevantResults];
    DataTable table = new DataTable();
    table.Load(resultTable, LoadOption.OverwriteChanges);
    int n = resultTable.TotalRows;
    The variable "qry" is a valid SQL Query with the relevant clauses.
    I am using a foreach loop to go through "table" (a DataTable), and so I do not think that I have a "one-off error".
    Any suggestions would be most welcome.

    So in results you have all items but when you are loading it into table (type DataTable) you are loosing one last record.
    1) First you check what data you are getting in resultTable - as you are specifying RelevantResult
    2) Check last index of data in ResultTable collection and try to find out the last index ResultTable, or try to find last index of data in result table
    DataTable.Load method accepts parm of type IDataReader and IDatareader, there are cases it looses records if not read properly..check below links
    http://stackoverflow.com/questions/8396656/why-does-my-idatareader-lose-a-row
    http://msdn.microsoft.com/en-us/library/system.data.datatable.load(v=vs.110).aspx
    <hr> Mark ANSWER if this reply resolves your query, If helpful then VOTE HELPFUL <br/> <b><a href="http://insqlserver.com">Everything about SQL Server | Experience inside SQL Server </a></b>-<a href="http://insqlserver.com">Mohammad
    Nizamuddin </a>

  • Why some columns are not read into Power Pivot when reading data from a SQL query

    I have this SQL query that I want to use to read data to PowerPivot from:
    SELECT Score.FieldCount as fieldcount, Score.Record.GetAt(0) as predicted_gender, Score.Record.GetAt(1) as probability_of_gender,  Score.Record.GetAt(2)
    as probability_of_m,  
    Score.Record.GetAt(3) as probability_of_f,  Score.Record.GetAt(4) as customerkey
    FROM 
    SELECT * FROM dbo.myCLR1(
    dbo.MyCLR2('c:\fILES\MLSM.xml'), 
    'SELECT * FROM [dbo].[Customer]') Input
    ) Score
    After I click 'Finish' in "Table Import Wizard", I can only get 1 column (FieldCount) in Power Pivot window. Why don't I get the other 4 columns? If I save the result to a table I do get all columns but my goal is to dynamically present the result
    so that's not an option. Can anyone shed some light?
    Thanks,
    Chu
    -- Predict everything. http://www.predixionsoftware.com

    If I only pass in query as 
    SELECT * FROM dbo.myCLR1(
    dbo.MyCLR2('c:\fILES\MLSM.xml'), 
    'SELECT * FROM [dbo].[Customer]') Input
    I do get 2 columns (FieldCount and Record as shown below)
    -- Predict everything. http://www.predixionsoftware.com

  • Parse SQL: How to extract column names, table names from a SQL query

    Hi all,
    I have a requirement wherein a SQL query will be given in a text file.
    The text file has to be read (probably using text_io package), the SQL query needs to be parsed and the column names, table names and where clauses have to be extracted and inserted into separate tables.
    Is there a way to do it using PL/SQL ?
    Is there a PL/SQL script available to parse and extract column names, table names etc ?
    Pls help.
    Regards,
    Sam

    I think I jumped to conclusion too early saying it is completely possible and straight forward. But after reading through your post for one more time I realised you are not interested only in the column_names, also the table_names and the predicates .
    >
    SQL query needs to be parsed and the column names
    >
    The above is possible and straight forward using the dbms_sql package.
    I am pasting the same information as I did in the other forum.
    Check this link and search for Example 8 and .
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#sthref6136
    Also check the working example from asktom
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1035431863958
    >
    table names and where clauses have to be extracted
    >
    Now this is the tricky bit. You can extract the list of tables by getting the sql_id from v$sql and joining it with v$sql_plan. But sometimes you may not get all the results because the optimizer may choose to refine your query (check this link)
    http://optimizermagic.blogspot.com/2008/06/why-are-some-of-tables-in-my-query.html
    and you can get the predicate information from the same table v$sql_plan but I will leave that area for you to do some R&D.
    Regards
    Raj
    Edited by: R.Subramanian on Dec 10, 2008 3:14 AM

  • Creating reports in BI EE from PL/SQL query

    Please provide me solution of how to create reports in Oracle BI EE tool while using PL/SQL query block.
    Thanks
    Rajni Sharma

    Narender Singh wrote:
    Dear All,
    We are using Oracle APPS, we have two tier structure.I bet it is actually 3-tier & WebServer exists
    1) Application Tier
    2) Database Tier
    My requirement is to run a PL/SQL script to create directory structure in Unix box of Database Tier. I would be very grateful to person proving the input related to the same.
    I want to create directory structure to store different type of files.
    /usr/tmp/2000/jan/file1
    /usr/tmp/2000/jan/file2
    /usr/tmp/2000/jan/file3
    /usr/tmp/2000/jan/file4
    similarly, I have to create directory structure from year 2000- 2011 and for each year I have to 12 folder for months and then for each month I can have n number of file folders.
    We are using 11g database.
    Thanks in Advance!!
    Regards,
    Narender
    Edited by: Narender Singh on Aug 9, 2011 10:50 AMDBMS_SCHEDULER that invokes OS shell script

  • Alphabetical fetching from an SQL Query

    Hello,
    When I fetch from the following query:
    v_sql := 'SELECT REFERENCE_NO, COMPANY_NAME
    FROM CONSULTANTS
    ORDER BY COMPANY_NAME';
    The company names are in alphabetical order
    Something like:
    A
    B
    C
    D
    etc..
    Z
    then AFTER the capital letters come the a, b c
    Z
    then
    a
    then
    b
    etc..
    Is there a way to have the lower case letters such as "a" come right after ALL the "A"s
    Then the b's come after the B's
    Thanks
    Doug

    SQL> select col from (
      2  select 'a' col from dual
      3  union all
      4  select 'b' from dual
      5  union all
      6  select 'd' from dual
      7  union all
      8  select 'C' from dual
      9  union all
    10  select 'B' from dual
    11  union all
    12  select 'A' from dual
    13  )
    14  /
    C
    a
    b
    d
    C
    B
    A
    6 rows selected.
    SQL> select col from (
      2  select 'a' col from dual
      3  union all
      4  select 'b' from dual
      5  union all
      6  select 'd' from dual
      7  union all
      8  select 'C' from dual
      9  union all
    10  select 'B' from dual
    11  union all
    12  select 'A' from dual
    13  )
    14  order by upper(col), col
    15  /
    C
    A
    a
    B
    b
    C
    d
    6 rows selected.Rgds.

  • How to delete last user session from backend SQL query?

    Sometimes user session gets closed between some work by any reason.
    When next time that user logs to P6, he gets some error or particular functionaly dosen't work for that user or system hangs.
    In that case if i decided to clear last session history of that user from database, how to write SQL query?
    I don't want to delete all user sessions from table USESSION and USESSAUD, i simply want to delete last user session of particular user (E.g XYZ).

    I am quoting this from MOS Doc Id "Why would multiple session records be present in the User Sessions screen in P6 Web, and why might some of them have different IP addresses? (Doc ID 1600172.1)"
    Multiple sessions show up for users since different sections of P6 Web have their own sessions associated with them. If a user is authorized to use multiple areas of the software they will have multiple sessions each time they log in. Additionally, if users are closing their browsers before logging out of P6 Web Access you might see some past sessions still appearing in the list. These will eventually be cleared out by background jobs, however you can also reset the sessions in the software by clicking the "Reset User" link (Administer > User Sessions > Manage User Sessions), or by choosing the "Reset All Users" link (Administer > User Sessions > Manage User Sessions) to do this for all past sessions.
    Multiple IP addresses for sessions can happen when a user logs in from different machines. For example, a person may login at their desk, but then go to a colleagues workstation to discuss a project, and log in from there. Doing so will leave them with multiple IP addresses in the session records.
    Hope this helps
    Regards,
    Sachin Gupta

  • How to present results from a sql-query in java

    Hi - I'm having problems finding out how to present data from a database-query in a nice looking way in a JFrame. Want to present them similar to the way they are presented in the database. Is there an easy way doing this?

    Tried to use a JTable, but it's difficult when data in the table should be able to change all the time, i.e the number of rows. What is a Html-table? Can i use it in an application?

  • Returning operation, table and column from a sql query

    Hi,
    I am working on Oracle 10g and i have to do achieve something like this.
    i have to create procedure or functions which will accept a SQL query and will return following :
    1).  Operation like 'SELECT', 'INSERT', 'UPDATE', 'DELETE' etc.
    2).  Column names
    3).  Table involved.
    One way to achieve this would be through hard parsing of string which might be time consuming. So do we have any in-built oracle package or function for the same job ?
    Regards,
    Vikas Kumar

    Check for DBMS_SQL package and DESCRIBE_COLUMNS procedure in that package.
    You might need a combination of this package and Hard parsing of the input string.
    For operation you can trim any space and brackets using TRIM function and then you can extrcat first 6 characters using SUBSTR for Operation.
    I have not worked or used DBMS_SQL so wont be able to help you much on this.
    Here is the link for DBMS_SQL
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#i1026120
    Regards
    Arun

  • Chart not getting columns from the SQL Query with InlineTransform(xsl)

    Hi All,
    I am using MII 12.0 . I tried to use the mii standard xsl for converting rows into columns by  Inline Transform in a SQL Query.
    while executing the Query it is giving me the correct output but i tried to load the same Query in a IChart there it is not showing me the available columns that i can able to see in simple executiion and chart is also not plotting it keeps on loading.
    Thanks in Advance.

    Hi LinoVaz,
    Some things to try for testing purposes -
    1. Don't do any Data Mapping of the query columns
    2. If a SQL Query, you may need to change the Server Scaling to use Global AutoScale.
    I found that when I mapped the inline-transformed query into a bar chart display template, and hit the Refresh button, only the first column name show in the Column Names area.  If I mapped it, I got only that column.  If I didn't map any columns, I got them all.
    Let me know if you find similar results.  I think this is likely a bug, so you may consider using a Business Logic Transaction and an XacuteQuery to accomplish the same result.
    Kind Regards,
    Diana Hoppe
    Edited by: Diana Hoppe on Mar 25, 2011 11:46 AM

  • How to get the number value from Oracle SQL Query?

    Hi All,
    I have a query which will return the below output.
    LINE_NUMBER           STRING
    10000                        A,B,C,D
    20000                       X,Y,Z,D
    80000                       P,Q,R,A
    130000                     E,R,T,Y
    210000                     Y,R,G,H
    1300000                   F,H,Y,UThe above output i need to get only the number 1, 2, 8, 13, 21, 210 for each row. Can you give the solution for that?
    Thanks

    Another wild guess
    SQL>  with t as (
    select '10000                        A,B,C,D' str from dual union all
    select '20000                       X,Y,Z,D' str from dual union all
    select '80000                       P,Q,R,A' str from dual union all
    select '130000                     E,R,T,Y' str from dual union all
    select '210000                     Y,R,G,H' str from dual union all
    select '1300000                   F,H,Y,U' str from dual
    select str, rtrim(regexp_substr(str,'\d+'),0) nums from t
    STR                                  NUMS                               
    10000                        A,B,C,D 1                                  
    20000                       X,Y,Z,D  2                                  
    80000                       P,Q,R,A  8                                  
    130000                     E,R,T,Y   13                                 
    210000                     Y,R,G,H   21                                 
    1300000                   F,H,Y,U    13                                 
    6 rows selected.

  • Script task to convert output from a sql query into send mail task body formatting

    SSIS 2008R2 Version
    Code from script task
       Microsoft SQL Server Integration Services Script Task
       Write scripts using Microsoft Visual C# 2008.
       The ScriptMain is the entry point class of the script.
    using System;
    using System.Data;
    using Microsoft.SqlServer.Dts.Runtime;
    using System.Windows.Forms;
    namespace ST_29dd6843bd6c4aee9b1656c1bbf55ba8.csproj
        [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
        public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
            #region VSTA generated code
            enum ScriptResults
                Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
                Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
            #endregion
            public void Main()
                Variables varCollection = null;
                string header = string.Empty;
                string message = string.Empty;
                Dts.VariableDispenser.LockForWrite("User::gsEmailMessage");
                Dts.VariableDispenser.LockForWrite("User::gsWebserviceName");
                Dts.VariableDispenser.LockForWrite("User::gsNoOfCallsInADay");
                Dts.VariableDispenser.LockForWrite("User::gsCalledBySystem");
                Dts.VariableDispenser.GetVariables(ref varCollection);
                //Set the header message for the query result
                if (varCollection["User::gsEmailMessage"].Value == string.Empty)
                    header = "Hi, Count is greater then 50 :\n\n";
                    //header = "Execute SQL task output sent using Send Email Task in SSIS:\n\n\n";
                    header += "----------------------------------------------------------------------------------------------------------------------" + "\n";
                    header += string.Format("{0}\t\t\t\t{1}\t\t{2}\n", "WebService Name", "No Of Calls In A Day", "Called By System");
                    header += "----------------------------------------------------------------------------------------------------------------------" + "\n";
                    varCollection["User::gsEmailMessage"].Value = header;
                //Format the query result with tab delimiters
                     message = String.Format("<HTML><BODY><P>{0}</P><P>{1}</P><P>{2}</P></BODY></HTML>",
                                            varCollection["User::gsWebserviceName"].Value,
                                            varCollection["User::gsNoOfCallsInADay"].Value,
                                            varCollection["User::gsCalledBySystem"].Value);
                varCollection["User::gsEmailMessage"].Value = varCollection["User::gsEmailMessage"].Value + message + "\n";
                Dts.TaskResult = (int)ScriptResults.Success;
    Above code will return data in below format and then i send this output in aemail using send mail task.
    Hi, count is greater then 50 :
    WebService Name                                                         
    No Of Calls In A Day                        Called By System
    WebServiceone                                                     1                             
    Internetbutiken
    WebServiceGetdetailstwo                                                  1                             
    Internetbutiken
    Servicenamethree                                                            2                             
    MOB
    As you can see above code is not in align as if we service name is shorter then 2nd column get disallign and its not look good.I need output should be like below.
    Hi, count is greater then 50 :
    WebService Name                                                         
    No Of Calls In A Day                        Called By System
    WebServiceone                                                              1                             
    Internetbutiken
    WebServiceGetdetailstwo                                              1                             
    Internetbutiken
    Servicenamethree                                                          2                             
    MOB
    Please suggest something...
    Thanks 
    SR_MCTS

    See code explained here
    http://microsoft-ssis.blogspot.in/2013/08/sending-mail-within-ssis-part-2-script.html
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    This will not help.As I am not creating smtp connectin ,send from ,send to in script task.I am just creating email body from sql output.

Maybe you are looking for

  • Using time machine backup on disk connected to airport extreme router?

    So I've read a number of articles about using an external hard drive connected to the airport extreme base station as a time machine backup. The thing is that I'm writing this in august 09, most of the articles (which say the feature is officially un

  • Deleting apps from download queue

    How can I delete a paid app from my download queue? It was not successful as I did not have billing details. I have an app which I bought for $1.99 (I think) on my iPhone. When I wanted to install it on my iPad, I found an app with a same screenshot

  • Can't drive mapping with jre1.4.2_11

    I need to drive mapping with jre1.4.2_11 in Windows applications but I can't. If you change the file java.policy with all permission then the drive mapping works properly. But if you want to add permission only for the drive mapping?? Anyone knows ab

  • Flash CS5.5 + AIR2.7 : How can i affect the localizations of the App Binary

    Hi, i have already produced an iPhone App with CS5.5 / AIR2.7 and it was accepted by Apple. BUT: In the Store there is a whole bunch of languages listed, which are announced to be supported. How can i disable them? The App is only for english und ger

  • Add attributes and rename the attributes according to the need

    I am a new developer to jdev, I need more help. I design a salary db, the attributes are employee_id,employee_name,pay_type1, pay_type2,pay_type3,pay_type4,pay_type5,... Now salary kind is only pay_type1, so in view we only select emplyee_id, employe