wood burning stoves*
The moose likes JDBC and the fly likes class.forName n statement interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "class.forName n statement interface" Watch "class.forName n statement interface" New topic
Author

class.forName n statement interface

clyde melly
Ranch Hand

Joined: Sep 04, 2003
Posts: 152
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();
clyde melly
Ranch Hand

Joined: Sep 04, 2003
Posts: 152
c'mon reply!!!
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

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.

Dave
clyde melly
Ranch Hand

Joined: Sep 04, 2003
Posts: 152
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.
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by clyde melly:

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



    Shailesh
    [ June 22, 2005: Message edited by: Shailesh Chandra ]

    Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: class.forName n statement interface
     
    Similar Threads
    role of drivers
    how desktop pane works
    jdbc
    Class.forName() ?
    When Class.forName() executes what internally happens?