Erro no Banco de Dados

oi gostaria de saber se alguem poderia me ajudar a solucionar este erro q fica dando qd faço a consulta no Banco de Dados

Unknown column 'm.esp' in 'on clause' at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666) at com.mysql.jdbc.Connection.execSQL(Connection.java:2994) at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936) at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030) at consulta.Roteiro.Relatorio(Roteiro.java:238) at consulta.Roteiro$1.actionPerformed(Roteiro.java:122) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source) at java.awt.Component.processMouseEvent(Unknown Source) at javax.swing.JComponent.processMouseEvent(Unknown Source) at java.awt.Component.processEvent(Unknown Source) at java.awt.Container.processEvent(Unknown Source) at java.awt.Component.dispatchEventImpl(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source) at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source) at java.awt.Container.dispatchEventImpl(Unknown Source) at java.awt.Window.dispatchEventImpl(Unknown Source) at java.awt.Component.dispatchEvent(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source)

O erro fica dando na seguinte parte do codigo:

try { Connection conexao = DriverManager.getConnection("jdbc:mysql://localhost/roteiros", "root", "root"); PreparedStatement sql = null; if (!cid.getSelectedItem().equals(" ")){ sql = conexao.prepareStatement("SELECT r.cod, r.ordem, r.med, m.nome AS nome_m, e.nome AS nome_e, m.end, r.cid, m.tel1, m.tel2, m.tel3, r.tec, t.nome FROM rot r, medico m, tecnico t LEFT JOIN esp e ON m.esp = e.cod WHERE r.med = m.cod AND r.tec = t.cod AND r.cid = ?"); sql.setString(1, (String)cid.getSelectedItem()); } else if (!med.getSelectedItem().equals(" ")){ String medi = ""; String medico = (String)med.getSelectedItem(); int i = 0; while (medico.charAt(i) != ' '){ medi = medi + medico.charAt(i); i++; } sql = conexao.prepareStatement("SELECT r.cod, r.ordem, r.med, m.nome AS nome_m, e.nome AS nome_e, m.end, r.cid, m.tel1, m.tel2, m.tel3, r.tec, t.nome FROM rot R, medico M, tecnico T LEFT JOIN esp e ON m.esp = e.cod WHERE r.med = m.cod AND r.tec = t.cod AND r.med = ?"); sql.setInt(1, Integer.parseInt(medi)); } else if (!tec.getSelectedItem().equals(" ")){ String tecni = ""; String tecnico = (String)tec.getSelectedItem(); int i = 0; while (tecnico.charAt(i) != ' '){ tecni = tecni + tecnico.charAt(i); i++; } sql = conexao.prepareStatement("SELECT r.cod, r.ordem, r.med, m.nome AS nome_m, e.nome AS nome_e, m.end, r.cid, m.tel1, m.tel2, m.tel3, r.tec, t.nome FROM rot t, medico m, tecnico t LEFT JOIN esp e ON m.esp = e.cod WHERE r.med = m.cod AND m.tec = t.cod AND r.tec = ?"); sql.setInt(1, Integer.parseInt(tecni)); } else if (!rot.getText().equals("")){ sql = conexao.prepareStatement("SELECT r.cod, r.ordem, r.med, m.nome AS nome_m, e.nome AS nome_e, m.end, r.cid, m.tel1, m.tel2, m.tel3, r.tec, t.nome FROM rot r, medico m, tecnico t LEFT JOIN esp e ON m.esp = e.cod WHERE r.med = m.cod AND r.tec = t.cod AND r.cod = ?"); sql.setInt(1, Integer.parseInt(rot.getText())); } ResultSet rs = sql.executeQuery();

Se alguem puder me ajudar ficarei agradecida,

Atenciosamente,

Jaqueline

A mensagem de erro diz que a coluna “m.esp” é desconhecida.
Vi que num dos selects você deu o alias “medico M” ao invés de “medico m”. Pode ser que a sua aplicação esteja caindo neste if e o problema esteja no uppercase. Tente mudar o alias para “medico m” daquele if.

eu já arrumei este detalhe mas o erro ainda continua dando eu tinha esquecido de arrumar , se fosse isso tinha q ter parado mas num parou.

Bem, o campo “esp” existe na tabela “medico”, certo?

Consegue debugar e nos falar exatamente em qual desses selects está passando qdo dá o erro?!

Em todos os selects o erro da no m.esp.

Vc tentou rodar esse msm SQL no MySQL Query Browser pra ver se o erro se repete?

Teria como vc mandar o script desse BD pra criarmos aqui (só a estrutura, sem os dados)?

É meio complicado verificar um SQL se não conhecemos a estrutura das tabelas envolvidas nele…