1
How do I record only one of these fields select
?
Statement stmt = con.createStatement();
ResultSet RS = null;
RS = stmt.executeQuery("select codplpag, descricao from pcplpag ORDER BY 1,2");
while(RS.next()){
// ListaBox.addItem(RS.getString("codplpag")+" / " + RS.getString("descricao"));
ListaBox.addItem(RS.getString("codplpag" )+" / " + RS.getString("descricao"));
}
Update:
int registro = stmt.executeUpdate("update pcpedc set codplpag =" +ListaBox.getSelectedItem().toString()+
"where numped=" + consPCPEDC);
One space left before WHERE, I wonder if that’s all?
– bfavaretto
worse than not @bfavaretto, it brings me the selected item and everything else, amis when I put to save it saves the description along with the number "codplpag"+ the description "Description" ai it from the error
– Wesley Costa
The best thing you can do is use
PreparedStatement
and avoid creating their query concatenating variables.– Renan Gomes
My advice would be not to use two distinct pieces of information as an item from
ListBox
. But if you want to insist on this you would have to separate the two data to use only what matters. Thiscodplpag
has fixed size guaranteed? What is?– Maniero
has the size of 2 fields
– Wesley Costa
how do I separate the data?
– Wesley Costa
You can get a substring of the selected item by taking the first characters or counting the separator you used (" /"). But it can get better than that. What is the type/class of
ListaBox
?– Caffé
What is size of 2 fields? It would be 2 characters?
– Maniero