4
Well, I use the eclipse and I’m trying to connect a Mysql database with my project, my code, compared to other tutorials I found, it’s perfect, and it’s this:
package pack;
import java.sql.*;
import javax.swing.JOptionPane;
public class Banco {
public Statement stm;
public ResultSet rs;
public Connection conn;
public String Driver = "com.mysql.jdbc.Driver";
public void Conecta(){
System.setProperty("jdbc.Drivers", Driver);
try {
conn = DriverManager.getConnection("jdbc:mysql:meu_caminho", "meu_login", "minha_senha");
JOptionPane.showMessageDialog(null, "Conectado!");
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Erro!" + "\n" + e.getMessage());
}
}
public void Desconecta(){
try {
conn.close();
} catch (SQLException e) {
JOptionPane.showMessageDialog(null, "Erro ao fechar!");
}
}
}
the problem is it gives the error "No suitable driver found for meu_caminho"
the solution everyone says is that I have to put the jdbc driver in my project, I tried to download the java connector on the Mysql site itself, but it is an msi file, and what all the tutorials say are to put the . jar, but I can’t find this jar at all, the only one I found was a 4shared link, a version 5.1.13 in . jar, but even after I add the library, the same error continues giving...
someone knows where I get this . jar?
Note: about this . jar I found, I put it in the project, I right-clicked, I went into properties, java build path, I added . jar, was created the Referenced folder Libraries, and when I open, there is the "com.mysql.jdbc.Driver" and yet, it does NOT connect...
Math, I got this answer from another question. I wanted to leave just one comment, from Java SE 6 (JDBC 4.0) explicit calls to
Class.forName
are no longer required (see documentation on Drivermanager). Have a strong galley using Java 5 or legacy drivers around :).– Anthony Accioly
Yes, I had read this in the link of the duplicate question of this aq, then I was going to test to see if it proceeds, but I haven’t had time yet. Curious fact so many people having this kind of problem.
– Math