Driver MySQL

5 respostas
ramilani12

Pessoal estou com problemas ao inserir no Banco de Dados MySQL estava usando a ponte jdbc:odbc num banco de Dados MYSQL, ele gera o auto incremento mas não leva os dados , ai baixei no site do Java o driver para o mysql -> mysql-connector-java-3.1.8 ,mas nao estou conseguindo registra ele CLASSPATH como faço …
Tá gerando uma porrada de erro olha só ?

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

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 DBController.<init>(DBController.java:24)

at DBController.getConnection(DBController.java:33)

at Posto.<init>(Posto.java:40)

at FramePrincipal$2.actionPerformed(FramePrincipal.java:82)

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.AbstractButton.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)

at javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.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 Posto.incluirPosto(Posto.java:148)

at Posto.access$2(Posto.java:145)

at Posto$2.actionPerformed(Posto.java:111)

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)

5 Respostas

fmeyer

é web ou swing ?

se for web coloca no diretorio WEB-INF/libs

se for swing adiciona o jar no class path …

ramilani12

É, swing mas como faço ? adicionar o jar no classpath

ramilani12

Consegui adicionar os jar no projto pelo eclipse , mas ta dando mesma coisa gera o autoincremento mas nao salva os dados no mysql , quando eu estava usando ponte jdbc:odbc estava dando isso tbm … estou fazendo isso pra incluir …

private void incluirPosto(ActionEvent ae){

limpaForm();

try{

Statement stmt = con.createStatement();

String aQuery=INSERT INTO Posto (Nome,Endereco) VALUES(’”+tNome.getText()+"’,’"+tEnd.getText()+"’)";

int i=stmt.executeUpdate(aQuery);

<a href="//con.commit">//con.commit</a>();

stmt.close();

JOptionPane.showMessageDialog(null,Posto Gravado - Sucesso);

limpaForm();

}catch(SQLException ex){

System.err.println("Erro I/O.\n "+ex.getMessage());

}

}

A Classe DBController

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.SQLException;
public class DBController {

private static Connection con;

private static DBController db;
private DBController() {
	try{
		
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		//con = DriverManager.getConnection(url,"root","");
		con = DriverManager.getConnection("jdbc:mysql://localhost/posto?user=root&password=");
	}catch(Exception ex){
		ex.printStackTrace();
	}
}
public static Connection getConnection(){
	if(db==null){
		db=new DBController();
	}
	return con;
}

}

Prq será que não leva os dados ?

ramilani12

já resolvi o problema burrada minha !

Tche

como vc resolveu: =]

Criado 5 de maio de 2005
Ultima resposta 22 de fev. de 2008
Respostas 5
Participantes 3