Could someone explain to me what exactly a driver is and what it would be like to use it with mysql?
A short time ago I started watching some JBDC videos and the word "Drivers" is constantly used, and with the answer from google about what it is, it is not enough for me to understand how it is linked with mysql.
This is sample code which is what I learned so far with mysql in java.
try {
//1. Conectarse a la base de datos.
Connection coneccion = DriverManager.getConnection("jdbc:mysql://localhost:8889/Java", "root", "root");
//2.Crear el statement.
Statement statement = coneccion.createStatement();
//3.Generar una consulta.
ResultSet resultado = statement.executeQuery("SELECT * FROM Productos");
//4.Leer el resulset.
while ( resultado.next() ) {
String idArt = resultado.getString(1);
String seccionArt = resultado.getString(2);
String nombreArt = resultado.getString(3);
System.out.println("ID: " + idArt + ". Seccion: " + seccionArt + ". Nombre: " + nombreArt );
}
In terms of Java and JDBC, a jar or library that allows communication with a particular database engine is called a driver. It happens that JDBC is an interface framework that Java provides to communicate with any database engine, what the database engine provider (or the community) does is provide an implementation of this group of interfaces to allow access and communication to the database engine in question.
In your case, you are using a driver to connect to MySQL, you can use the official driver (jar) provided by mysql on its download page.
In the same way, to communicate with another database server, you must use the appropriate driver (jar). For example, to communicate with a SQL Server database there are two options: 1) the official Microsoft driver (jar) and 2) a driver (jar) called jTDS that is maintained by the community, each one has its pros and cons and the choice of one or the other will depend on those particular needs.