Results 1 to 6 of 6

Thread: [JAVA] query results in a combobox and jtextfield

  1. #1
    Join Date
    Feb 2009
    Posts
    84

    [JAVA] query results in a combobox and jtextfield

    exposing the two problems hoping for your answer:
    1) I want to list in each row of a combobox names and names for doctors. I managed to do so only for names (or names only), but not both. This is what I should change:

    / / from the form where I make a combobox called the Database class that contains the functions (I think that goes well)

    Code:
    Database db = new Database (); 
    Public Vector doctor; 
    ..... 
    Medical db.elenco_medicine = (); 
    for (int i = 0; i <medico.size (); i + +) ( 
    Combo_dottori.addItem (medico.get (i));) 
    
    / / This is the function in class Database 
    
    Elenco_medicine Vector () ( 
    Vector res = new Vector (); 
    ris.add ( "empty"); 
    String q = null; 
    String error = start (); 
    q = "SELECT cognome_medical FROM doctor"; 
    try ( 
    Statement st = connection.createStatement (); 
    ResultSet rs = st.executeQuery (q); 
    if (rs.isBeforeFirst ()) ( 
    ris.removeAllElements (); 
    ris.add ( "All the doctors");) 
    else ( 
    ris.removeAllElements (); 
    ris.add (error); 
    ) 
    while (rs.next ()) ( 
    ris.add (rs.getString ( "cognome_medical")); 
    )) Catch (Exception e) ( 
    / / SE generates a SqlException RETURNED TO THE CLIENT TO INFORM 
    ris.removeAllElements (); 
    ris.add (e.ToString ()); 
    ) 
    return res; 
    )
    The query to return the names of the doctors is simple (just add nome_medico after SELECT), but as I change the function to put your name and surname in the same row?

    2) I need to set some text as jTextField the results of a query ... I need practice in the consideration for the queries in the combobox ke do so:

    Code:
    for (int i = 0; i <medico.size (); i + +) ( 
    Combo_dottori.addItem (medico.get (i));)
    I hope to be clear..... otherwise ask...

  2. #2
    Join Date
    Dec 2008
    Posts
    161

    Re: [JAVA] query results in a combobox and jtextfield

    Once retrieved from the database resultset with names and names of doctors in the combobox do not have to do is enter the string corresponding to the name + surname.

    I did not understand well where you have difficulty, in the code.

  3. #3
    Join Date
    Feb 2009
    Posts
    84

    Re: [JAVA] query results in a combobox and jtextfield

    I tried like this:

    Code:
    Elenco_medici Vector () ( 
    Vector res = new Vector (); 
    ris.add ( "empty"); 
    String q = null; 
    String error = start (); 
    q = "SELECT cognome_medico` `` `FROM` nome_medico doctor `";// NEW QUERY 
    try ( 
    Statement st = connessione.createStatement (); 
    ResultSet rs = st.executeQuery (q); 
    if (rs.isBeforeFirst ()) ( 
    ris.removeAllElements (); 
    ris.add ( "All the doctors");) 
    else ( 
    ris.removeAllElements (); 
    ris.add (error); 
    ) 
    while (rs.next ()) ( 
    ris.add (rs.getString ( "cognome_medico")); 
    ris.add (rs.getString ( "nome_medico "));// ADDITION 
    )) Catch (Exception e) ( 
    / / SE generates a SqlException RETURNED TO THE CLIENT TO INFORM 
    ris.removeAllElements (); 
    ris.add (e.ToString ()); 
    ) 
    return res; 
    )

    Please check and let me know where should i make changes..

  4. #4
    Join Date
    Mar 2008
    Posts
    232

    Re: [JAVA] query results in a combobox and jtextfield

    Hey Aamin this is not specific you just try to put the error message you are getting while running the program

    Post at least the mistakes that you split in output and then try to understand what's the Problem.

  5. #5
    Join Date
    Feb 2009
    Posts
    84

    Re: [JAVA] query results in a combobox and jtextfield

    I had no excuse under the program by mistake .... I javaSQLException ... not find the 'column' cognome_medical, but with the function written in the first post found, with only cognome_medical in the query.

    edit: the name by moving the first and last name in the query ris.add not found in the column nome_medical.

  6. #6
    Join Date
    Mar 2008
    Posts
    232

    Re: [JAVA] query results in a combobox and jtextfield

    ... gives me error javaSQLException ... can not find the 'column' cognome_medical, but with the function written in the first post found, with only cognome_medical in the query.
    Perfect if you understood that you raised a query because there is an error due to incorrect syntax of the query when the transform to recover the values of two fields instead of just one practice you almost solved the problem.

    The step would be that you are missing, documentation to hand (or video ), To verify the correct SQL syntax for a SELECT.

    q = "SELECT cognome_medical ','nome_medico FROM doctor";// NEW QUERY
    Missing a comma?

Similar Threads

  1. Replies: 4
    Last Post: 20-01-2012, 11:56 AM
  2. Query in java classes
    By Aaliya Seth in forum Software Development
    Replies: 5
    Last Post: 26-02-2010, 01:34 AM
  3. Query with Date in java
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 03:55 AM
  4. Query regarding use of ActionListener in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 16-11-2009, 10:56 AM
  5. Replies: 9
    Last Post: 01-02-2009, 02:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,446,432.91955 seconds with 17 queries