Can't get the table display my results

OK After some good hours of debugging i am able to display my results on JTable for my queries. But i got another problem now. When i select Query2 from my JComboBox and click on execute button nothing happens, same thing for query3 and 4. The only thing which works is QUERY1 why? what am i doing wrong?
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import java.awt.event.ActionEvent;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.Vector;
public class DatabaseProgramming extends JFrame implements ActionListener{
     static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
     static final String DATABASE_URL = "jdbc:mysql://localhost/employees";
     static final String USERNAME = "jhtp6";
     static final String PASSWORD = "jhtp6";
     private static final String QUERY1 = "SELECT * FROM employees WHERE DEPARTMENTNAME = 'SALES'";
     private static final String QUERY2 = "SELECT * FROM hourlyEmployees WHERE hours >= '30'";
     private static final String QUERY3 = "SELECT * FROM commissionEmployees ORDER BY commissionRate DESC";
     private String names[] = {"QUERY1", "QUERY2", "QUERY3", "QUERY4"};
     private Connection connection;
     private ResultSet resultSet;
     private Statement statement;
     private ResultSetMetaData metaData;
     private JTable resultTable;
     private JComboBox queryBox;
     private JButton button;
     private int number;
     private boolean connectedDatabase = false;
     private DefaultTableModel dtm;
     public static void main(String[] args) {
          DatabaseProgramming frame = new DatabaseProgramming();
          frame.setVisible(true);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     public DatabaseProgramming() {
          super("Testing Database");
          setLayout(new FlowLayout());
          //dtm = new DefaultTableModel(getColumnName(number),0);
          //     statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
               //         ResultSet.CONCUR_READ_ONLY);
          queryBox = new JComboBox(names);
          queryBox.setEditable(false);
               //queryBox.addActionListener(this);
               button = new JButton("EXECUTE");
               resultTable = new JTable();
               button.addActionListener(this);
               add(queryBox);
               add(button);
               add(resultTable);
               //add(result);
               setSize(400,400);
      public void actionPerformed(ActionEvent e)  {
          String selection = (String)queryBox.getSelectedItem();
                    if(selection.equals(names[0]))
                    validateQuery(QUERY1);
                    if(selection.equals(QUERY2))
                         validateQuery(QUERY2);
                    if(selection.equals(QUERY3))
                         validateQuery(QUERY3);
      public void validateQuery(String query) {
               try {
                    Class.forName(JDBC_DRIVER);
                    connection = DriverManager.getConnection(DATABASE_URL, USERNAME, PASSWORD);
                    System.out.println("Yay Database Connected");
                Vector col = new Vector();
                Vector data = new Vector();
           statement = connection.createStatement();
              resultSet = statement.executeQuery(query);
              metaData = resultSet.getMetaData();
              number = metaData.getColumnCount();
              for(int i=1; i<=number; i++)
                   col.addElement(metaData.getColumnName(i));
              while(resultSet.next()) {
                   Vector row = new Vector();
                   for(int i=1; i<=number; i++)
                        row.addElement(resultSet.getObject(i));
                   data.addElement(row);
             resultTable.setModel(new DefaultTableModel(data,col));
             resultTable.revalidate();
           catch ( SQLException sqlException )
              sqlException.printStackTrace();
              System.exit( 1 );
           catch(ClassNotFoundException e) {
                e.printStackTrace();
           finally
              try                                                       
                 statement.close();                                     
                 connection.close();                                    
              catch ( SQLException sqlException )
                 JOptionPane.showMessageDialog( null,
                    sqlException.getMessage(), "Database error",
                    JOptionPane.ERROR_MESSAGE );
                 System.exit( 1 );
}

One last question how can i display the columnName on my JTable? Add the table to a scroll pane and the scroll pane to the frame.

Similar Messages

  • We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 version

    We are upgrading from 8.3 to 9.2. How can i get the table(record) structure changes between these 2 versions. I am not able to find it in Oracle support.

    My guess is you want to upgrade HR8.3 to 9.2 - and that is not one jump upgrade. You will need to go HRMS 83 to 90
    (PeopleSoft Enterprise HRMS 8.3x to 9.0 Upgrade (Doc ID 747333.1) and then 90 to 92 (PeopleSoft Human Capital Management 9.0 to 9.2 Upgrade Home Page (Doc ID 1536087.1)
    Each these MOS pages contains the Demo to Demo Compare Reports that show the data structures changes between the releases.
    Hope it helps.

  • How can we get the table name...

    Hi All,
    How can we get the actual table name for an argument if its datatype is %ROWTYPE.
    For Ex :
    function ACCOUNT_UPDATE (account_no number,
    person person%rowtype,
    amounts dbms_describe.number_table,
    trans_date date)
    return accounts.balance%type;
    In the above function 'ACCOUNT_UPDATE', for argument person the datatype is 'person%rowtype'.
    Is there any way to get the name from Data Dictionary tables.
    I tried using All_Arguments and DBMS_DESCRIBE, I can able to get all the individual fields of %ROWTYPE by I could not able to know the exact table name thru the DD.
    my requirement is dynamically I need to declare a variable for the argument datatype.
    Your help is highly appreciated.
    Thanks

    hi vinay,
    this is the easiest way to find the tablename of a particular field.
    t.code:XD01.
    enter.
    select the kunnr field.
    press F1.
    the top of the screen u will get 'Technical setting icon.
    select that one.then u will get tablename,fieldname,parameter id also.
    if helps give the rewards.
    regards,
    akash.k

  • How can I get the username displayed in BW Web-Report?

    Hello all,
    I try to get the username displayed in BW-Report such as 'welcome <username>'.
    Maybe you can give me a suggestion how to do it.
    I appretiate your answer.
    Regards
    Vivian

    you can use the following javascript within the webtemplate to get the user id
    <script language=javascript>
    var user_name ='<object>
             <param name="OWNER" value="SAP_BW"/>
             <param name="CMD" value="GET_ITEM"/>
             <param name="NAME" value="TEXTELEMENTS_USER"/>
             <param name="ITEM_CLASS" value="CL_RSR_WWW_ITEM_TEXT_ELEMENTS"/>
             <param name="DATA_PROVIDER" value="DP"/>
             <param name="GENERATE_CAPTION" value=""/>
             <param name="ELEMENT_TYPE_1" value="COMMON"/>
             <param name="ELEMENT_NAME_1" value="SYUSER"/>
             <param name="ONLY_VALUES" value="X"/>
             ITEM:            TEXTELEMENTS_USER
    </object>';
    </script>
    Regards
    Raja

  • How can I get the table control up arrow or down arrow SCROLL OK_CODE?

    Dear All,
    I want get the table control up or down Scroll OK_CODE (not button, is arrow click), But I debugged have not found when I click the up or down scroll.
    Please give me some help.
    Thanks

    Hi Sun,
    PBO..
                               Loop with control T1.
                       module get_Looplines.
                    Endloop.
                        Module get_looplines.
                          Looplines = sy-loopc.      "<< by using this you can get the scroll bar...
                        Endmodule.
    if you wan the ok_code for scroll bar in table control...
    the ok_code is not generated for scroll bar..
    but if you do not clear the ok_code in PBO it will carries the ok_code when ever you press scroll bar up and down...same ok_code is repeated..
    Regards,
    Prabhudas

  • How can I get the table name of my column?

    I'm using the JDK 1.3 trying to get a table name of a column from a result set. Regardless of what driver I'm using (ODBC Bridge/Oracle) I always get a null returned. Does this method work?
    If not, if I'm doing an SQL query that uses more than 1 table and each table has a return of the same column name, how do I distinguish which table the column is from. Thanks

    You can use ResultSetMetaData interface and method
    String getTableName(int column)
    This should return you the table name.
    To get ResultSetMetaData object, you can use
    ResultSetMetaData getMetaData()
    method of ResultSet interface.
    HTH

  • How can I get the Tables in my report to update their field lists?

    I am working with Crystal Reports 2008, and I have a ReportDocument loaded in a .NET project.
    I want to update the field lists of the tables (stored procedures) used in the report.  I am calling "VerifyDatabase()", but this does not update the field lists.  Through the designer, I accomplish this by going to the Database -> Set Datasource Location..., then clicking on the stored procedure (i.e. table) in the report, clicking on the stored procedure under the database in the bottom pane, and then clicking "Update".
    How can I accomplish this in code?
    Thanks for any help.

    Hello,
    You have to use RAS and the replace connection method. The Report Engine does not have the ability.
    Search forums for "ReplaceConnection_Click" and you'll find sample code that should work for you.
    Thank you
    Don

  • How can I get the table name of a field..

    Hi,
    If we know the table name we can find all the fileds from it
    using desc <tablename>.
    But, I would like to find table name of a known field's name.
    Where all these fields are storing in the database.
    THanks in Advance,
    Srinivasulu.

    ALL_TAB_COLUMNS
    rgds, APC

  • Can't get the tables normally using RFC call to BC

    SAP Business Connector Developer.
    ->IDataUtil.getIDataArray function (can't work properly using RFC CALL)( I think it's the source of problem)
    I use the SAP Business Connector Developer(4.7) to get data from db2.
    and I create a JAVA service in th BC named writeData,
    the most important snippet shown below.
      // Get IDataCursor to manipulate pipeline
      IDataCursor idcPipeline = pipeline.getCursor();       
      // If the value is not an IData[], returns null.
      IData[] recordListIn = IDataUtil.getIDataArray( idcPipeline, "ORICONTENT" );
      idcPipeline.first( "CHECKEDDATE" );
      String checkedDate  = (String) idcPipeline.getValue();
      idcPipeline.first( "CPYCOD" );
      String cpycod= (String) idcPipeline.getValue();
       /* if ( recordListIn == null )
              errMsg += "No Input Data";
              recLen=0;
      }else{
            recLen= recordListIn.length;
      try{
         recLen= recordListIn.length;
      catch(Exception ed){
         errMsg += "\r\nExceptionIn: " + ed.getMessage();
         recLen=0;
      In BC, the variable recLen can get the record list length normally, but if i call the function in the SAP,
    the system throw an exception, the ed.getMessage() return value NULL.
      I think the problem which the rfc can't work properly is that the method IDataUtil.getIDataArray execute unnormal.
      I have set value to ORICONTENT(record list) in SAP, and it can return the record that i have set to the SAP System,
    and in the java service,  I have return another record list creating using the following spippet, It can work normally.
    com.wm.app.b2b.server.DBConnection db
            =new com.wm.app.b2b.server.JDBCConnection(driverString,userName,
                    userPwd);
              com.wm.util.Values ida= db.execSQL(selectSql);
              idcPipeline.insertAfter("OUTDATAREC", ida );
              db.close();
    I have tried some adjustments, but nothing can work.
    The reason That I use one jave service instead of standard flow services is I have to transfer data to more than two db2 servers, and I have to keep the consistency.
    Attached please find the SAP test page (using se37) and the java service code.
    May you kindly help me to solve this problem, I don't know the real reason, and which is very emergent, but i can't changed Priority(If I changed it ,the page is unuseful).
    Additional,I have added some code shown below,
    idcPipeline.first( "ORICONTENT" );
    java.lang.Object curObj = idcPipeline.getValue();
    if (curObj == null)
    errMsg +=" object is null ";
    else{
    errMsg +=" object isnt null ";
    try{
    recordListIn=(IData[])curObj;
    } catch(Exception ed){
    errMsg += " ExceptionOBj: " + ed.getMessage();
    recLen=0;
    In BC, everything is ok. but call the function in the sap, Show the following informatin:
    Object isnt null
    ExceptionOBj: com.wm.util.Table

    Hi, Mei Xie
    you mentioned 'In BC, everything is ok. but call the function in the sap, Show the following informatin: ....', I think the return value of RFC is null.
    have you tried to add a try catch around the RFC call, like following:
    try {
      IDataCursor idcPipeline = pipeline.getCursor();
    } catch (Exception ...)
    I'm not familiar with jave, only worked on C#, but I think try to catch the exception on RFC call is worth doing. Maybe it will descript some information around the problem.
    By the way, can you tell me which RFC/BAPI you are calling?
    I don't know what 'In BC, everything is ok.' mean. I have no experience on BC, only used dotnet connector. So can you explain how you use BC for me?
    thanks

  • Can I get the date to display along with the day and time

    can I get the date displayed with the day of week and time?

    Hi Mary, you can, but what version of OSX are you running on what Mac?
    See if this helps for starters...
    http://paulstamatiou.com/how-to-display-date-in-os-x-menu-bar

  • I can't get my table to remain uniform.

    I am a novice at creating webpage so please bear with me. I
    am trying to put together a Football Schedule page for a football
    league's website. I have uploaded the table. (Team_schedule ) to my
    mysql database via ms access. Status ... OK.
    Then I created the connection in dreamweaver so it would help
    me with the php coding . Staus ....Ok it works.
    Now I’d like to have the dreamweaver repeat the table
    info – Status.....Ok it works.
    However , when I put the record set in the table . I
    can’t get the table to NOT expand. I need the text t to
    remain the size I made it .
    Here is a link of how I’d like it to look
    [S=http://seminoles.cstv.com/sports/m-footbl/sched/fsu-m-footbl-sched.html[/S]https://
    FSU
    FOOTBALL WEBSITE[/S]
    Also it repeats all the records until it fills up the page.
    Can someone please help.

    I haven't looked at that URL, but will try to help.
    By default, an HTML table cell will expand to show all the
    content you put into it, even if you set a specific pixel width. If
    you have lots of text in a cell, you can try setting a font and
    font size using CSS to control the size of the text.
    Also, I'm assuming you are using the Repeat Region Server
    behavior. That behavior allows you to specify how many records per
    page to show. It sounds like you selected all records, rather than
    a specific number. Try updating the behavior to show only a certain
    number of records and inserting a Record Navigation Bar to
    navaigate through the entire recordset.

  • How to get the table of value field? and can we expand the technical limits

    Dear
    I have created value field in COPA with KEA6. And now, I need the table which the value fields are saved. Yet, I have tried a lot to find it and get failure? Can any guy help me? Please tell me how to get the table of a value field.
    And another question is that, can we extend the technical limits for the number of value field for ECC6.0?
    We have a note for R.4.x Please see below:
    OSS note 160892
    You can display the length of a data record using Transaction KEA0 ('Maintain Operating Concern'). After you have navigated to the 'Characteristics Screen' or to the 'Value field Screen' choose menu path 'Extras -> Technical Limits'.
    The maximum displayed here under 'Length in bytes on the DB' is the maximum length permitted by the Dictionary. The reserve required for the release upgrade must be subtracted from this value.
    To increase the allowed number of the value fields, increase the value that is assigned to field ikcge-bas_max_cnt (FORM init_ikcge_ke USING fm_subrc, approx. line 165) in Include FKCGNF20. It specifies the number of the possible value fields. The corresponding part of the source code is attached to the note as a correction.
    David Sun
    Regards!

    how to extend the limit of value numbers? please see the original question.

  • How can I get iTunes to display the tracks from a CD in their original (album) order?

    To be absolutely honest, I don't really understand what this box is for, so I shall just use it to repeat and expand on my question. (I have already sent a "Feedback" comment on the same topic).
    How can I get iTunes to display the tracks from a CD in their original (album) order?
    It seems to me that there is something very basic wrong with the way iTunes handles CD Tracks.
    Professionally produced CD tracks are seldom if ever in a randomised order. Why then does iTunes seem unable to display the tracks in the order they appear on the original CD source - whether from a personally owned CD or from a download from the iTunes Store?
    Some music demands a specific, non-alphabetic sequence in order to make sense. Why does it seem that iTunes only offers Alphabetic, or reverse alphabetic order - both of which make a nonsense of the original, often intended order of tracks?
    Why not replace the so-called "cover-art" in the bottom left hand corner if the iTunes window - which, while it may look attractive to some, gives the barest of information concerning the original disc, with a list of the original CD tracks in their original order, so that the user can easily reestablish the order in which they should be played.
    As I would expect legibility might be a problem with doing this, why could not the original contents, (in their original order), at least, be displayed when the "cover art" is double clicked-on - the result of which at present gives me an enlarged version of the "Cover Art". While on the subject of the contents of the source disc, what about all the album notes which someone takes trouble to write in order to increase the appreciation of the music on the CD and the listener's general background knowledge of the artists involved. Such notes, it seems to me, have considerable intrinsic value in their own account. I would, I think, normally be prepared to buy such "Sleeve notes" - so long as a "taster" was supplied (as it is for the music) - for something like the cost of a single 'Tune" on iTunes.
    These two aspects let Apple iTunes down enormously, in my opinion. I think that by chopping even quite protracted sequences of music up into bits does no one any favours - except perhaps Apple's already quite substantial bank balance. People have to be aware that two and a half, to three and a half minutes is a very short time to develop a piece of worthwhile music, and that there are many, many composers, not all of whom are alive today who have written music that huge masses of mankind value for the enrichment of their lives and the human condition in general.
    Please make the viewing of iTunes tracks in their correct order by default possible. By all means have the alphabetical variations available as offering a different approach to the music, but not the sole approach to it - PLEASE.
    Frustratedly yours
    Alan Whitaker
    PS I work at my old 24" iMac Intel Core 2 machine which runs OS "Tiger" - because it is more beautiful to look at, the screen is more pleasant to work on, and because, in some ways it is more capable (it will run FreeHand MX without needing a "patch"), than my more recent 21.5" which runs "Snow Leopard". (I don't find it that much slower, either).

    Dear Mike
    Thanks for the support. I am utterly amazed that after all the hype about how good iTunes is that it cannot play a downloaded CD in the correct order, and that what that order should be is not available directly from within one's own iTunes installation. (I know that one can go back to the iTunes Store to check what the order should be, but having downloaded the tracks surely iTunes is clever enough to retrieve this important information.
    My iTunes to differ from yours in that I have also noticed that it seems unable to download copies of my "talking books" in the correct order either. But in my case it downloads them - from a CD - in order, but with the first track downloaded first - so that it appears at the bottom of the column of tracks so that it would get played last! (At least this is, while being inexplicable, a relatively "logical" bit of blundering and because of this is relatively easy to put right!).
    I like many genres of music, some of which are not really programmed except perhaps by the artist performing them. I know that Frank Sinatra was very careful to programme his album songs to obtain a particular effect and in relation to the keys of the music. iTunes presumes to know better.
    Film scores may be totally randomly put together, in some cases, but in others the order is vital to one's appreciation of the music as a whole and how it relates to the plot of the film.
    In symphonic music most works are divided into sections and are conceived by the composer that way. Some individual sections may gain a life of their own if played separately, but they are never complete in the sense that the composer envisaged them without being placed in their proper context.
    Opera and probably most choral music too, is similar except that the words may well become meaningless if the order is changed at the whim of a piece of ill-written computer code, while ballet music has to be heard totally within its sequential context or it becomes meaningless.
    Finally, I would venture that iTunes, by jumbling up the order of the tracks as recorded on a CD, does an immense disservice, not only to the music on a particular CD, but to music in general, by expressing everything in terms of "Songs" - which it seems to interpret as stand-alone items of between 2 and 4 minutes whatever the genre. Even the way the iTunes publicity speaks of how many "songs" it can store instead of how many minutes or hours of recorded sound. This has to be another brick in the wall of "dumming-down" of people's expectations, and the shortening of their attention spans.
    I don't know about anyone else, but I feel betrayed by Apple over this. Perhaps the look, feel and general presentation of an item are not the most desirable features of a consumer product. Maybe it should be judged more on it fitness for the purpose for which it was sold. There is one other possibility - that Apple are trying to redefine "Music" - and that everything that lasts longer than about 3.5 minutes or is in the form of what could for want of a better term be called symphonic in the broadest sense is something else - not "Music" within Apple's new definition, at all!
    Well that's off my chest! now I can get down to creating some sort of order in my iTunes Libraries, knowing that I have to reconsult all the sources in order to confirm the source playing order.
    Anyway thanks again. At least I know that it is not just me
    alanfromthatcham

  • In the topmost Firefox menu with File,Edit,View,History,Bookmarks, I can not get the list of bookmarks to display as they did before. The Bookmarks menu does not open up into the list of bookmarks.

    I am running Mac os 10.6.8 and Firefox 6.0.1 on a MacBook Pro and on a desktop Macintosh.
    The large computer displays a list of bookmarks when you click on the uppermost Bookmarks menu.
    The MacBook Pro displays the following when you click on the Bookmarks word in the top menu:
    "Show all Bookmarks, Bookmark this Page, Bookmark all Tabs and an icon with a blue dot next to Bookmarks Toolbar with an arrow to the right and below that it says Unsorted Bookmarks.
    There is no display of the list of bookmarks from which I can chose as I do on the larger desktop macintosh computer.
    How can I get the list of bookmarks to show as a list when I click the Bookmarks menu?

    A possible cause is a problem with the file places.sqlite that stores the bookmarks and the history.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    You can also try to move (delete) the Firefox plist file.<br />
    See [http://www.macfixit.com/article.php?story=20060606082246983 How .plist files become corrupt and troubleshooting the results]
    Go to "Library > Preferences" and remove the plist file for Firefox (org.mozilla.firefox.plist).

  • How to get the table name of a field in a result set

    hi!
    i have a simple sql query as
    select tbl_customerRegistration.*, tbl_customerAddress.address from tbl_customerRegistration, tbl_customerAddress where tbl_customerAddress.customer_id = tbl_customerRegistration.customer_ID
    this query executes well and gets data from the database when i get ResultsetMetaData from my result set (having result of above query) i am able to get the field name as
    ResultSetMetaData rsmd = rs.getMetaData();//rs is result set
    String columnName = rsmd.getColumnName(1);
    here i get columnName = "Customer_id"
    but when i try to get the tabel name from meta data as
    String tableName = rsmd.getTableName(1); i get empty string in table name....
    i want to get the table name of the respective field here as it is very important to my logic.....
    how can i do that.....
    please help me in that regard as it is very urgent
    thanks in advance
    sajjad ahmed paracha
    you may also see the discussion on following link
    http://forum.java.sun.com/thread.jspa?threadID=610200&tstart=0

    So far as I'm aware, you can't get metadata information about the underlying tables in a query from Oracle and/or the Oracle drivers. I suspect, in fact, that the driver would have to have its own SQL parser to get this sort of information.
    I'm curious though-- how do you have application logic that depends on the name of the source table but not know in the application what table is involved? Could you do something "cheesy" like
    SELECT 'tbl_customerRegistration' AS tbl1_name,
           tbl_customerRegistration.*
    ...Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for

  • How do I log the time in hours, minutes and seconds to a table

    Hi I'm a relatively new user of Labview. I am currently writing a program that logs the temperature of an oven and the current time to a table and graph. I am using a GPIB card to communicate with the oven. I have used the Get Date/Time string to get

  • SAP PORTAL Time-Out Settings / BO iView Reports..?

    We have created BO object-specific iView requests in SAP PORTAL based on Ingo's posting.... SAP BusinessObjects Enterprise & SAP Enterprise Portal - Part 3 of 4 Currently, just posting some small CR4E and Analysis for Office (*Design Studio will be a

  • How  to verify yum configuration  in OEL . is there any way  to rollback the package

    Hi , How we can verify  the yum configurtion . is there any way to rollback the package using yum Also  let me know how to rollback packages that upgraded using up2date .

  • Unable to set a property

    Hi, In my .jnlp file I'm trying to set a system property in the resources section, via: <property name="jnlp.aname" value="avalue" /> and in my code I am using System.out.println(System.getProperty("jnlp.aname")) and I am only getting 'null' for outp

  • Transparency Issues in Adobe Flash Cs3

    Insert>New Symbol>Movie Clip File>Import>Import to stage>then I import my series of images I made in Photoshop that I saved as transparent png. images.  that have transparent backgrounds. Then I go back to scene 1. I insert some keyframes on the time