I know about 2 ways to connect to database well I will divided it into 2 methods (Method1 and Method 2)
Connection connection;
public void getConnectionMethod1() {
try {
Class.forName("net.sourceforge.jtds.jdbc.Driver");
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/latihan","sa","denni");
} catch (SQLException e) {
}
}
public void getConnectionMethod2() {
try {
DriverManager.registerDriver(new net.sourceforge.jtds.jdbc.Driver());
connection = DriverManager.getConnection("jdbc:jtds:sqlserver://localhost:1433/latihan","sa","denni");
} catch (SQLException e) {
}
}
My question is; is there any difference between them ? Method 1 uses Class.forName While method 2 uses registerDriver
What is the advantages and disadvantages between them?
NOTE : I can only use PreparedStatement on Method 2.