Ir ao conteúdo
  • Cadastre-se

Esdras Fragoso

Membro Júnior
  • Posts

    6
  • Cadastrado em

  • Última visita

Reputação

1
  1. String NomeTurma = (String) turmaCampoBox.getSelectedItem(); String idturma = idTurma(NomeTurma); String idTurma(String Nome) throws Exception{ String s = "SELECT idTurma FROM `turma` WHERE Nome='"+Nome+"'"; PreparedStatement stmt = Conexao.abrir().prepareStatement(s); ResultSet rs = stmt.executeQuery(s); String id; if(rs.next()){ id = rs.getString("Nome"); }else{ id = null; } return id; } Alguém pode me ajudar, me informando onde esta o Erro? Pois o codigo SQL roda no banco e aparece o idTurma, mas quando copio o codigo SQL e coloco para rodar no JAVA acontece esse erro!
  2. Faça uma função que solicite que o usuário escreva nomes repetidamente até que o usuário digite "sair", para encerrar o programa. Para fazer este procedimento, use if/then/else..
  3. /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package projetofinal; import java.util.ArrayList; import javax.swing.table.AbstractTableModel; /** * * @author FRAGOSO */ public class ModeloTabela extends AbstractTableModel{ private ArrayList linhas = null; private String[] colunas = null; public ModeloTabela(ArrayList lin, String[] col){ setLinhas(lin); setColunas(col); } public ArrayList getLinhas(){ return linhas; } public void setLinhas(ArrayList dados){ linhas = dados; } public String[] getColunas(){ return colunas; } public void setColunas(String[] nomes){ colunas = nomes; } public int getColumnCount(){ return colunas.length; } public int getRowCount(){ return linhas.size(); } public String getColumnName(int numCol){ return colunas[numCol]; } public Object getValueAt(int numLin, int numCol){ Object[] linha = (Object[])getLinhas().get(numLin); return linha[numCol]; } } public void preecherTabela(String SQLAluno) throws Exception{ ArrayList dados = new ArrayList(); String [] Colunas = new String [] {"Nome","Telefone","CEP"}; /* PreparedStatement stmt = Conexao.abrir().prepareStatement(SQLAluno); ResultSet rs = stmt.executeQuery(SQLAluno); */ dados.add(new Object[]{"Esdras","Programação WEB","8.0"}); dados.add(new Object[]{"Esdras","Programação WEB","8.0"}); dados.add(new Object[]{"Esdras","Programação WEB","8.0"}); dados.add(new Object[]{"Esdras","Programação WEB","8.0"}); dados.add(new Object[]{"Esdras","Programação WEB","8.0"}); ModeloTabela modela = new ModeloTabela(dados, Colunas); notas.setModel(modela); notas.getColumnModel().getColumn(0).setPreferredWidth(200); notas.getColumnModel().getColumn(0).setResizable(false); notas.getColumnModel().getColumn(1).setPreferredWidth(200); notas.getColumnModel().getColumn(1).setResizable(false); notas.getColumnModel().getColumn(2).setPreferredWidth(100); notas.getColumnModel().getColumn(2).setResizable(false); notas.getTableHeader().setReorderingAllowed(false); notas.setAutoResizeMode(notas.AUTO_RESIZE_OFF); notas.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } Gostaria de saber onde estou errando? O que deve fazer para os nomes das colunas aparecerem!
  4. CREATE TABLE IF NOT EXISTS `mydb`.`questao` ( `idquestao` INT NOT NULL AUTO_INCREMENT, `Questao` VARCHAR(500) NOT NULL, `Resposta` VARCHAR(500) NOT NULL, `Nivel` INT NOT NULL, `Assunto` VARCHAR(45) NOT NULL, `Score` DOUBLE NOT NULL, `disciplina_id` INT(11) NOT NULL, `disciplina_Turma_idTurma` INT NOT NULL, PRIMARY KEY (`idquestao`, `disciplina_id`, `disciplina_Turma_idTurma`), INDEX `fk_questao_disciplina1_idx` (`disciplina_id` ASC, `disciplina_Turma_idTurma` ASC), CONSTRAINT `fk_questao_disciplina1` FOREIGN KEY (`disciplina_id` , `disciplina_Turma_idTurma`) REFERENCES `trabalhofinal`.`disciplina` (`id` , `Turma_idTurma`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB Onde é que existe esta tal restrição na cham primaria que me informa o mysql. #1215 - Não pode acrescentar uma restrição de chave estrangeira
  5. Como eu uso o this.dispose(); sempre que tento da erro! Sair.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); this.dispose(); } }); sempre que eu tento colocar isto dentro do Action da erro! adicionado 4 minutos depois @zOpek Meu amigo deu Certo aqui obrigado.
  6. Como fechar esta tela sem fechar toda aplicação public class CadastroTurma extends JFrame{ private JLabel nome = new JLabel("Nome:"); private TextField nomeTextFild = new TextField(); private JButton CadastrarTurma = new JButton("Cadastrar"); private JButton Sair = new JButton("Sair"); public CadastroTurma(){ super("Projeto"); this.setSize(716,130); this.setVisible(true); Container tela = getContentPane(); tela.setLayout(null); this.setContentPane(tela); this.setLocationRelativeTo(null); this.setResizable(false); tela.add(nome); nome.setBounds(9, 9, 50, 25); tela.add(nomeTextFild); nomeTextFild.setBounds(72, 9, 300, 25); tela.add(CadastrarTurma); CadastrarTurma.setBounds(400, 9, 100, 25); tela.add(Sair); Sair.setBounds(512, 9, 100, 25); Sair.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); } }

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...