The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

interface Connection in package java.sql

Posted by Arjan van der Meer on December 15, 2000 at 4:36 PM

Hello,

I am wondering why the following code works.
Im my understanding Connection is an interface in class java.sql.
An interface cannot be instantiated andshou;d have all its methods
implemented by the clss that implements the interface.
But which class implements Connection here ? Where is the
implementation of the method createStatement() ?

Thank you for your help,

Arjan
import java.sql.*;

class Employee
{
public static void main (String args [])
throws SQLException
{
// Load the Oracle JDBC driver
DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

// Connect to the database
// You must put a database name after the @ sign in the connection URL.
// You can use either the fully specified SQL*net syntax or a short cut
// syntax as ::. The example uses the short cut syntax.
Connection conn =
DriverManager.getConnection ("jdbc:oracle:thin:@dlsun511:1721:dbms733",
"scott", "tiger");

// Create a Statement HOW IS THIS POSSIBLE ??
Statement stmt = conn.createStatement ();

// Select the ENAME column from the EMP table
ResultSet rset = stmt.executeQuery ("select ENAME from EMP");

// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us