Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let's decode the lines of your code block:</p> <pre><code>1. DriverManager.registerDriver 2. (new oracle.jdbc.driver.OracleDriver()); 3. conn = java.sql.DriverManager.getConnection( 4. "jdbc:oracle:thin:username/password@machine.us.company.com:1234:dbSID"); </code></pre> <p>Line 2: </p> <p>Creates a new instance of <code>oracle.jdbc.driver.OracleDriver</code>, a JDBC <code>Driver</code> for the Oracle database. A JDBC driver implements the interfaces and classes defined by the JDBC API that programmers use to connect to a database and perform queries. </p> <p>Line 1</p> <p>Registers the instance of the <code>oracle.jdbc.driver.OracleDriver</code> to the <a href="http://java.sun.com/javase/6/docs/api/java/sql/DriverManager.html" rel="nofollow noreferrer"><code>DriverManager</code></a> class which is the traditional management layer of JDBC, working between the user and the drivers. It handles establishing a connection between a database and the appropriate driver. </p> <p>Line 3:</p> <p>Now that the communication layer between the JDBC application and the database is ready, you can create a connection by calling <a href="http://java.sun.com/javase/6/docs/api/java/sql/DriverManager.html#getConnection%28java.lang.String%29" rel="nofollow noreferrer"><code>getConnection()</code></a> method of the <a href="http://java.sun.com/javase/6/docs/api/java/sql/DriverManager.html" rel="nofollow noreferrer"><code>DriverManager</code></a> class.</p> <p>Line 4:</p> <p>This is the "connection string" or "database URL". This <code>String</code> identifies the database you want to connect to. The scheme of this URL is specific to the database provider and/or the driver (here, Oracle and its "thin" driver). </p> <hr> <p>Note that prior to Java 6, calling <code>Class.forName</code> was the preferred way to load and register a JDBC Driver. It was the responsibility of the <code>Driver</code> to call <a href="http://java.sun.com/javase/6/docs/api/java/sql/DriverManager.html#registerDriver%28java.sql.Driver%29" rel="nofollow noreferrer"><code>DriverManager.registerDriver</code></a>. </p> <blockquote> <p>[...] All <code>Driver</code> classes should be written with a static section (a static initializer) that creates an instance of the class and then registers it with the <code>DriverManager</code> class when it is loaded. Thus, a user would not normally call <code>DriverManager.registerDriver</code> directly; it should be called automatically by a <code>Driver</code> class when it is loaded.</p> </blockquote> <p>Check the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/drivermanager.html" rel="nofollow noreferrer">Driver Manager</a> chapter from the JDBC documentation for more details.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload