OLa ao conectar ao BD Firebird recebo a seguinte mensagem:
Table unknown
porem a referida tabela existe no firebird
o mais estranho eh q um select so funciona no firebird se eu colocar o nome da tabela em aspas:
select * from “Aluno” , mas no java nao tenho como colocar o nome da tabela em aspas, pois da um erro.
Alguem sabe como contornar esse erro?
Erro ao dar select no firebird
C
4 Respostas
C
Olá cedemir,
Pra usar aspas dentro de uma String, coloque ":
Até mais, 
B
Boa tarde!
Se você utilizar o IB Expert, você irá perceber que não é necessário colocar o nome da tabela entre aspas.
por exemplo:
o SQL pode ser executado assim:
SELECT * FROM VEICULO tando no SQL Editor do IBExpert como através do JDBC, sem a necessidade do uso das ASPAS.
Passa o código java para dar uma verificada.
Um abraço
C
Agradeco aqueles que tiveram paciencia de explicar, pois soi meio "noob "
Ja estou conseguindo conectar, porrem criei 6 botoes para o deslocamento dos registros na tela e somente o primeiro esta executando o codigo
import java.sql.<em>;
import javax.swing.</em>;
import java.awt.<em>;
import java.awt.event.</em>;
import java.awt.GridLayout;
class JanelaAluno extends JFrame implements ActionListener {
private JLabel L1,L2,L3,L4,L5,L6,L7,L8,L9,L10,L11,L12,L13,L14,L15,L16,L17,L18,L19,L20,L21,L22,L23,L24,L25,L26,L27,L28,L29,L30,
L31;
private JButton b1,b2,b3,b4,b5,b6;
private JTextField txtId,txtIdentidade,txtNome,txtSexo,txtEndereco,txtBairro,txtMunicipio,txtCep,txtFone,txtCelular,txtData_Nasc,txtNatural,txtRegistro,txtFolha,txtLivro,txtReligiao,txtVacina,txtPai,txtProfPai,txtMae,txtProfMae,txtObservacoes,txtDesconto,
txtIdentidade_Pai,txtCPF_Pai,txtIdentidade_Mae,txtCPF_Mae,txtFator_RH,txtAlergico_Medicamento,txtObs_Alergia;
private Conexao Comandos;
private ResultSet rs;
private JPanel p1;
private JPanel p2;
private JPanel p3;
private Container framepane;
public JanelaAluno(int a, Conexao Cod) {
Comandos = Cod;
framepane= this.getContentPane();
framepane.setLayout(new BorderLayout());
p1= new JPanel(new GridLayout(30,1));
L1 = new JLabel("Id_Aluno");
L2 = new JLabel("Identidade");
L3 = new JLabel("Nome");
L4 = new JLabel("Sexo");
L5 = new JLabel("Endereço");
L6 = new JLabel("Bairro");
L7 = new JLabel("Município");
L8 = new JLabel("Cep");
L9 = new JLabel("Fone");
L10 = new JLabel("Celular");
L11 = new JLabel("Data_Nasc");
L12 = new JLabel("Natural");
L13 = new JLabel("Registro");
L14 = new JLabel("Folha");
L15 = new JLabel("Livro");
L16 = new JLabel("Religião");
L17 = new JLabel("Vacina");
L18 = new JLabel("Pai");
L19 = new JLabel("ProfPai");
L20 = new JLabel("Mãe");
L21 = new JLabel("ProfMae");
L22 = new JLabel("Observações");
L23 = new JLabel("Desconto");
L24 = new JLabel("Identidade_Pai");
L25 = new JLabel("CPF_Pai");
L26 = new JLabel("Identidade_Mae");
L27 = new JLabel("CPF_Mae");
L28 = new JLabel("Fator_RH");
L29 = new JLabel("Alergico_Medicamento");
L30 = new JLabel("Obs_Alergia");
p1.add(L1); p1.add(L2);
p1.add(L3); p1.add(L4);
p1.add(L5); p1.add(L6);
p1.add(L7); p1.add(L8);
p1.add(L9); p1.add(L10);
p1.add(L11); p1.add(L12);
p1.add(L13); p1.add(L14);
p1.add(L15); p1.add(L16);
p1.add(L17); p1.add(L18);
p1.add(L19); p1.add(L20);
p1.add(L21); p1.add(L22);
p1.add(L23); p1.add(L24);
p1.add(L25); p1.add(L26);
p1.add(L27); p1.add(L28);
p1.add(L29); p1.add(L30);
p2= new JPanel(new GridLayout(30,1));
txtId = new JTextField(10);
txtIdentidade=new JTextField(12);
txtNome=new JTextField(40);
txtSexo=new JTextField(1);
txtEndereco=new JTextField(50);
txtBairro=new JTextField(15);
txtMunicipio=new JTextField(25);
txtCep=new JTextField(8);
txtFone=new JTextField(15);
txtCelular=new JTextField(15);
txtData_Nasc=new JTextField(10);
txtNatural=new JTextField(25);
txtRegistro=new JTextField(10);
txtFolha=new JTextField(5);
txtLivro=new JTextField(6);
txtReligiao=new JTextField(10);
txtVacina=new JTextField(30);
txtPai=new JTextField(40);
txtProfPai=new JTextField(20);
txtMae=new JTextField(40);
txtProfMae=new JTextField(20);
txtObservacoes=new JTextField(40);
txtDesconto=new JTextField(10);
txtIdentidade_Pai=new JTextField(12);
txtCPF_Pai=new JTextField(11);
txtIdentidade_Mae=new JTextField(12);
txtCPF_Mae=new JTextField(11);
txtFator_RH=new JTextField(05);
txtAlergico_Medicamento=new JTextField(01);
txtObs_Alergia=new JTextField(40);
p2.add(txtId); txtId.setEditable(false);
p2.add(txtIdentidade);txtIdentidade.setEditable(false);
p2.add(txtNome);txtNome.setEditable(false);
p2.add(txtSexo); txtSexo.setEditable(false);
p2.add(txtEndereco);txtEndereco.setEditable(false);
p2.add(txtBairro); txtBairro.setEditable(false);
p2.add(txtMunicipio);txtMunicipio.setEditable(false);
p2.add(txtCep); txtCep.setEditable(false);
p2.add(txtFone); txtFone.setEditable(false);
p2.add(txtCelular); txtCelular.setEditable(false);
p2.add(txtData_Nasc);txtData_Nasc.setEditable(false);
p2.add(txtNatural); txtNatural.setEditable(false);
p2.add(txtRegistro);txtRegistro.setEditable(false);
p2.add(txtFolha); txtFolha.setEditable(false);
p2.add(txtLivro); txtLivro.setEditable(false);
p2.add(txtReligiao); txtReligiao.setEditable(false);
p2.add(txtVacina); txtVacina.setEditable(false);
p2.add(txtPai); txtPai.setEditable(false);
p2.add(txtProfPai); txtProfPai.setEditable(false);
p2.add(txtMae); txtMae.setEditable(false);
p2.add(txtProfMae); txtProfMae.setEditable(false);
p2.add(txtObservacoes); txtObservacoes.setEditable(false);
p2.add(txtDesconto); txtDesconto.setEditable(false);
p2.add(txtIdentidade_Pai);txtIdentidade_Pai.setEditable(false);
p2.add(txtCPF_Pai); txtCPF_Pai.setEditable(false);
p2.add(txtIdentidade_Mae);txtIdentidade_Mae.setEditable(false);
p2.add(txtCPF_Mae); txtCPF_Mae.setEditable(false);
p2.add(txtFator_RH); txtFator_RH.setEditable(false);
p2.add(txtAlergico_Medicamento);txtAlergico_Medicamento.setEditable(false);
p2.add(txtObs_Alergia); txtObs_Alergia.setEditable(false);
p3= new JPanel(new GridLayout(1,6));
b1=new JButton(">>");
b2=new JButton("<<");
b3=new JButton("|<");
b4=new JButton(">|");
b5=new JButton("+10 reg.");
b6=new JButton("-10 reg.");
b1.setBackground(new Color(180,180,250));
b2.setBackground(new Color(180,180,250));
b3.setBackground(new Color(180,180,250));
b4.setBackground(new Color(180,180,250));
b5.setBackground(new Color(180,180,250));
b6.setBackground(new Color(180,180,250));
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
p3.add(b1); p3.add(b2);
p3.add(b3); p3.add(b4);
p3.add(b5); p3.add(b6);
framepane.add(BorderLayout.WEST,p1);
framepane.add(BorderLayout.CENTER,p2);
framepane.add(BorderLayout.SOUTH,p3);
setTitle("Navegação da tabela de Alunos");
setSize(650,600);
setLocation(100,100);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
try {
rs = Comandos.Select("SELECT * FROM \"Aluno\"");
rs.next();
atualizaCampos();
}catch(Exception f){
JOptionPane.showMessageDialog(null,"Erro no select de alterar \n"+f.toString(), "Alerta",JOptionPane.INFORMATION_MESSAGE );
}
}
public void actionPerformed(ActionEvent e) {
try {
if (e.getSource()==b1)
rs.next();
if (e.getSource()==b2)
rs.previous();
if (e.getSource()==b3)
rs.first();
if (e.getSource()==b4)
rs.last();
if (e.getSource()==b5)
rs.relative(10);
if (e.getSource()==b6)
rs.relative(-10);
atualizaCampos();
} catch(SQLException ex) {
// tratamento de erros durante a navegação
}
}
public void atualizaCampos() {
try {
if (rs.next()){
txtId.setText(rs.getString("Id_Aluno"));
txtIdentidade.setText(rs.getString("Identidade"));
txtNome.setText(rs.getString("Nome"));
txtSexo.setText(rs.getString("Sexo"));
txtEndereco.setText(rs.getString("Endereço"));
txtBairro.setText(rs.getString("Bairro"));
txtMunicipio.setText(rs.getString("Município"));
txtCep.setText(rs.getString("Cep"));
txtFone.setText(rs.getString("Fone"));
txtCelular.setText(rs.getString("Celular"));
txtData_Nasc.setText(rs.getString("Data_Nasc"));
txtNatural.setText(rs.getString("Natural"));
txtRegistro.setText(rs.getString("Registro"));
txtFolha.setText(rs.getString("Folha"));
txtLivro.setText(rs.getString("Livro"));
txtReligiao.setText(rs.getString("Religião"));
txtVacina.setText(rs.getString("Vacina"));
txtPai.setText(rs.getString("Pai"));
txtProfPai.setText(rs.getString("ProfPai"));
txtMae.setText(rs.getString("Mãe"));
txtProfMae.setText(rs.getString("ProfMae"));
//txtObservacoes.setText(rs.getString("Observações"));
txtDesconto.setText(rs.getString("Desconto"));
txtIdentidade_Pai.setText(rs.getString("Identidade_Pai"));
txtCPF_Pai.setText(rs.getString("CPF_Pai"));
txtIdentidade_Mae.setText(rs.getString("Identidade_Mae"));
txtCPF_Mae.setText(rs.getString("CPF_Mae"));
txtFator_RH.setText(rs.getString("Fator_RH"));
txtAlergico_Medicamento.setText(rs.getString("Alergico_Medicamento"));
//txtObs_Alergia.setText(rs.getString("Obs_Alergia"));
}
} catch(SQLException ex) {
}
}
}
B
<blockquote> try {
rs = Comandos.Select(“SELECT * FROM “Aluno””);
rs.next();
atualizaCampos();
}catch(Exception f){
JOptionPane.showMessageDialog(null,“Erro no select de alterar \n”+f.toString(), “Alerta”,JOptionPane.INFORMATION_MESSAGE );
}
Verifique se o método Comandos.Select(…) está implemnetado de maneira correta
Criado 23 de dezembro de 2006
Ultima resposta 28 de dez. de 2006
Respostas 4
Participantes 3
Alura POO: o que é programação orientada a objetos? Aprenda os conceitos básicos da programação orientada a objetos, como classes, objetos, herança, encapsulamento e polimorfismo, com exemplos.
Casa do Codigo Inteligencia Artificial e ChatGPT: Da revolucao dos... Por Fabricio Carraro — Casa do Codigo