What actually happens when we say Class.forName("driver").The internal working n processing.Also since statement is an interface what actually happens when we do statament stmt=connection.createStatement();
3 hrs isn't actually a long time to wait. Personally I was at work, but you'll find roughly a third of our visitors have been asleep during this period.
Class.forName() causes the class to be loaded by the ClassLoader, as long as it hasn't been loaded before. THis allows a statis block to be executed in the Driver class. The Driver Class is required to register itself with the DriverManager (therefore you shouldn't do this yourself). Hopefully all this happens invisibly to you.
Now, when you ask for the DRiverManager for a Driver, you pass in the jdbc-url. The DriverManager asks each of the registsred Drivers (can can have more than one at a time, you see) if they support this jdbc-url. When it finds one that does, it gets it to provide a Connection and returns it to the client (ie you).
You only know that the Connection returned implements the Connection interface, you do not know (or really need to know) what the implementing Class is. The Connection class gives you a Statement. Again, you don't need to know the specific Classes, you just need to know they behave like Connections, Statements and ResultSets. If you program like this you can often swap dtaabases with minimal effect on your application.
Joined: Sep 04, 2003
Thanx for ur reply and sorry for my impatient behaviour.The first answer explaination is spot on but still require some more explaination with the statement question.
still require some more explaination with the statement question.
Are you looking for something specific ???
Once a connection is established, it is used to pass SQL statements to its underlying database. The JDBC API does not put any restrictions on the kinds of SQL statements that can be sent;
The JDBC API provides three interfaces for sending SQL statements to the database, and corresponding methods in the Connection interface create instances of them. The interfaces for sending SQL statements and the Connection methods that create them are as follows:
Statement-created by the Connection.createStatement methods. A Statement object is used for sending SQL statements with no parameters.
createStatement methods-for a simple SQL statement (no parameters)
PreparedStatement-created by the Connection.prepareStatement methods. A PreparedStatement object is used for precompiled SQL statements. These can take one or more parameters as input arguments (IN parameters).
prepareStatement methods-for an SQL statement that is executed frequently
CallableStatement-created by the Connection.prepareCall methods. CallableStatement objects are used to execute SQL stored procedures-a group of SQL statements that is called by name, much like invoking a function.
prepareCall methods-for a call to a stored procedure