|
| ||||||||||
| Tags: combobox, database, java, jtextfield |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| [JAVA] query results in a combobox and jtextfield
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; ) 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));) |
|
#2
| |||
| |||
| 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
| |||
| |||
| 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
| ||||
| ||||
| 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
| |||
| |||
| 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
| ||||
| ||||
| Re: [JAVA] query results in a combobox and jtextfield Quote:
The step would be that you are missing, documentation to hand (or video ), To verify the correct SQL syntax for a SELECT. Quote:
|
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "[JAVA] query results in a combobox and jtextfield" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to assign and retrieve values from JTextField in java swing | Rao's | Software Development | 4 | 20-01-2012 10:56 AM |
| Query in java classes | Aaliya Seth | Software Development | 5 | 26-02-2010 12:34 AM |
| Query with Date in java | Gunner 1 | Software Development | 5 | 12-02-2010 02:55 AM |
| Query regarding use of ActionListener in java | beelow | Software Development | 3 | 16-11-2009 09:56 AM |
| Google search results for any query displays "This site may harm your computer". | itrama | Networking & Security | 9 | 01-02-2009 01:13 AM |