Erro de conexao no mysql

4 respostas
F

Oi pessoal,

Estou comproblemas para criar uma conexao com o mysql!! alguem pode me ajudar!! olhem o codigo:
String driverName = "com.mysql.jdbc.Driver"; 
            try{
               String url = "jdbc:mysql://localhost:3306/SGPA"; // a JDBC url
               String username = "root";
               String password = " ";

            
               Class.forName("driverName");//.newInstance();
               con = DriverManager.getConnection(url, username, password);
              
                
            }
           catch(Exception e){

              e.printStackTrace();
             //  JOptionPane.showMessageDialog(null,"Erro de acesso ao banco!",
            //  "Mensagem",JOptionPane.ERROR_MESSAGE);
            }
        }

Baixei o mysql-connector-java-3.0.15-ga.zip e instalei no jre/lib/ext.
O erro que esta dando ficou cortado!! existe alguma maneira de capturar este sem cortar?? mesmo assim vou enviar o erro tambem!!
erro:


at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
java.lang.NullPointerException
at servicos.ServCategoria.Cadastrar(ServCategoria.java:74)
at negocios.NegCategoria.CadastrarCategoria(NegCategoria.java:34)
at interfaces.GuiCategoria$1.actionPerformed(GuiCategoria.java:96)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:17
86)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(Abstra
ctButton.java:1839)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258
)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:245)
at java.awt.Component.processMouseEvent(Component.java:5100)
at java.awt.Component.processEvent(Component.java:4897)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483
)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)
at java.awt.Container.dispatchEventImpl(Container.java:1613)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

4 Respostas

M

tenta rodar teu código de uma IDE como o Eclipse, ai ele nao vai cortar o output … vai ajudar a gente :slight_smile:

F

Matheus, rodei o codigo no eclipse e o erro e o seguinte:

java.lang.ClassNotFoundException: driverName

at java.net.URLClassLoader$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

at java.net.URLClassLoader.findClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClass(Unknown Source)

at java.lang.ClassLoader.loadClassInternal(Unknown Source)

at java.lang.Class.forName0(Native Method)

at java.lang.Class.forName(Unknown Source)

at servicos.ServCategoria.conexao(ServCategoria.java:47)

at servicos.ServCategoria.Cadastrar(ServCategoria.java:77)

at negocios.NegCategoria.CadastrarCategoria(NegCategoria.java:34)

at interfaces.GuiCategoria$1.actionPerformed(GuiCategoria.java:95)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.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 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.pumpOneEventForHierarchy(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)

java.lang.NullPointerException

at servicos.ServCategoria.Cadastrar(ServCategoria.java:78)

at negocios.NegCategoria.CadastrarCategoria(NegCategoria.java:34)

at interfaces.GuiCategoria$1.actionPerformed(GuiCategoria.java:95)

at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)

at javax.swing.AbstractButton$ForwardActionEvents.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 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.pumpOneEventForHierarchy(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)
R

tente colocar no driver de conexão o seguinte “org.gjt.mm.mysql.Driver”

F
Consegui realizar a conexao com o banco com o seguinte código:
try{
	String url = "jdbc:mysql://localhost/sgpa";
	Class.forName("com.mysql.jdbc.Driver");
	con = DriverManager.getConnection(url);
            
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null,"Erro de acesso ao banco!",
            "Mensagem",JOptionPane.ERROR_MESSAGE);
        }
Criado 18 de outubro de 2004
Ultima resposta 20 de out. de 2004
Respostas 4
Participantes 3