Boa Tarde,
Estou iniciando em MySql.
Nao estou conseguindo adicionar na tabela, retorna que esta com erro no driver (com.mysql.jdbc.Driver) e (No suitable for driver found).
Baixai o Connector/J adicionei corretamente, o netbeans tambem esta conectando com o branco. a porta e usuarios estao ok.
Agradeco desde ja!
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author augusto
*/
public class JPrincipal {
private java.sql.Connection con;
private java.sql.Statement stmt;
public JPrincipal(){
try{
Class.forName("com.mysql.jdbc.Driver");
}catch(ClassNotFoundException e){
JOptionPane.showMessageDialog(null,"Erro"+e.getMessage());
}
String url = "jdbc:mysql://127.0.0.1:3306/usandoBanco";
String user = "root";
String passwd = "root";
try{
con = DriverManager.getConnection(url,user,passwd);
stmt = con.createStatement();
}catch(SQLException e ){
JOptionPane.showMessageDialog(null,"Erro: "+e.getMessage());
}
insertRecord();
}
public static void main(String[] args) {
new JPrincipal();
}
private void insertRecord() {
try {
stmt.executeUpdate("INSERT IN TO Livros VALUES(002,'O Simbolo Perdido')");
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,"Erro: "+ex.getMessage());
}
}
}
Exception in thread "main" java.lang.NullPointerException
at JPrincipal.insertRecord(JPrincipal.java:48)
at JPrincipal.
at JPrincipal.main(JPrincipal.java:43)
Java Result: 1