Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



[JAVA] query results in a combobox and jtextfield

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 31-03-2009
Member
 
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...

Reply With Quote
  #2  
Old 31-03-2009
Member
 
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.
Reply With Quote
  #3  
Old 31-03-2009
Member
 
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..
Reply With Quote
  #4  
Old 31-03-2009
Member
 
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.
Reply With Quote
  #5  
Old 31-03-2009
Member
 
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.
Reply With Quote
  #6  
Old 31-03-2009
Member
 
Join Date: Mar 2008
Posts: 232
Re: [JAVA] query results in a combobox and jtextfield

Quote:
... 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.

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

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 01:28 AM.