I was learning JDBC, only thing i don't get is class Class in following code.
Whether I delete Class.forName("com.mysql.jdbc.Driver")
or not, it works properly.
Could you explain what function is Class.forName("com.mysql.jdbc.Driver") in this part?
import java.sql.*;
public class JSP {
public static void main(String[] args){
Connection myConn = null;
Statement st= null;
ResultSet rs= null;
try {
Class.forName("com.mysql.jdbc.Driver");
myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/customer", "root", "Gspot");
st = myConn.createStatement();
String query = "select * from customers";
rs = st.executeQuery(query);
while(rs.next()){
System.out.println(rs.getString("name"));
}
} catch(SQLException e){
e.printStackTrace();
} catch(ClassNotFoundException e) {
System.out.println("wow");
}
}
}