estou pegando o id do item selecionado na combo... mais preciso inserir esse id no banco...
AO SELECIONAR A OPÇÃO NA COMBO E CLICAR EM SALVAR... O ID DAKILO QUE ESTA NA COMBO DEVERÁ SER INSERIDO NO BANCO
Alguem pode me ajudar?
meu metodo inserir:public boolean inserir(DomainObject domainObject) {
Ocorrencia ocorrencia = (Ocorrencia) domainObject;
try {
Connection conn = Conexao.getConnection();
String sql = "INSERT INTO ocorrencia VALUES (?,?,?,?,?,?,?)";
PreparedStatement pst = conn.prepareStatement(sql);
pst.setInt(1, ocorrencia.getIDOcorrencia());
pst.setString(2, ocorrencia.getDescricao());
pst.setString(3, ocorrencia.getData());
pst.setString(4, ocorrencia.getVeiculo().getPlaca());
pst.setString(5, ocorrencia.getCliente().getNomecli());
pst.setString(6,ocorrencia.getVeiculo().getNomeVeiculo());
//INSERIR O ID DO CAMPO QUE ESTA NA COMBOBOX AKI
pst.setInt(7,ocorrencia.getServicos().getTiposervico().getIdServico());
pst.executeUpdate();
pst.close();
conn.close();
} catch (Exception e) {
return false;
}
return true;
public List Combo() {
List<Ocorrencia> strList = new ArrayList<Ocorrencia>();
try{
Connection conn = Conexao.getConnection();
String sql = null;
sql = "select idservico,nomeservico from tiposervico ";
PreparedStatement pst = conn.prepareStatement(sql);
ResultSet rs = pst.executeQuery();
while(rs.next()){
Ocorrencia ocorrencia = new Ocorrencia();
Servicos servico = new Servicos();
TipoServico tipo = new TipoServico();
tipo.setIdServico(rs.getInt("idservico"));
tipo.setDescricaoServico(rs.getString("nomeservico"));
servico.setTiposervico(tipo);
ocorrencia.setServicos(servico);
strList.add(ocorrencia);
public class RegistroOcorrencia extends javax.swing.JFrame {
private int vetorindice[] = new int[300];
/** Creates new form RegistroOcorrencia */
public RegistroOcorrencia() {
initComponents();
DaoOcorrencia dao = new DaoOcorrencia();
List<Ocorrencia> listacombo = dao.Combo();
//int tam = listacombo.size();
jComboBox1.removeAllItems();
int i=0;
for(Ocorrencia oco : listacombo){
jComboBox1.addItem(oco.getServicos().getTiposervico().getDescricaoServico());
vetorindice[i] = oco.getServicos().getTiposervico().getIdServico();
i++;
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
Ocorrencia ocorrencia = new Ocorrencia();
Clientee cliente = new Clientee();
ocorrencia.setCliente(cliente);
Servicos servicos = new Servicos();
ocorrencia.setServicos(servicos);
Veiculo veiculo = new Veiculo();
ocorrencia.setVeiculo(veiculo);
TipoServico tiposervico = new TipoServico();
ocorrencia.setIDOcorrencia(Integer.parseInt(tfcodigo.getText()));
ocorrencia.setDescricao(tfdescricaoocorrencia.getText());
ocorrencia.setData(tfdata.getText());
ocorrencia.getVeiculo().setPlaca(tfplaca.getText());
ocorrencia.getCliente().setNomecli(tfcliente.getText());
ocorrencia.getVeiculo().setNomeVeiculo(tfveiculo.getText());
IFachada fachadaoco = (IFachada) new FachadaOcorrencia();
FachadaOcorrencia ocorre = new FachadaOcorrencia();
try{
fachadaoco.inserir(ocorrencia);
JOptionPane.showMessageDialog(null, "salvo");}
catch (Exception error){
}
}