I have done a basic copy-paste of code to connect to an oracle server here at work:
import java.sql.Connection;
import java.sql.DriverManager;
public class OracleClass {
protected String driverName = "oracle.jdbc.driver.OracleDriver";
protected Connection dbConnection;
protected String username = "someUsername";
protected String password = "somePassword";
protected String server = "MYSERVER";
protected String port = "1521";
protected String sid = "MYSID";
public OracleClass() {
String url = "jdbc:oracle:thin:@" + server + ":" + port + ":" + sid;
Class.forName(driverName); // What does this do???
dbConn = DriverManager.getConnection(url, username, password);
}
/**
* Other methods
*/
}
This works, connects, and I can query the database and get a ResultSet from it, but what does the Class.forName(DriverName)
line do? It is supposed to return a static class, but I am no assigning it to anything (which I would think I need to do). It looks like it is just doing nothing.
What does it do? Is it needed?