[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...
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.
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..
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.
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.
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?