JDBC Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 2.11

Connecting JdbcRowSet with a Connection URL

This section describes how to connect a JdbcRowSet object to a database server with a connection URL.

If a JdbcRowSet object is created without a connection to the database server, you can provide a connection URL string by calling the setUrl() method. A connection object will be created later by the JdbcRowSet object with DriverManager when you call the execute() method. Here is a sample sequence of method calls:

// Creating a JdbcRowSet object wihout connection
  JdbcRowSet jrs = new JdbcRowSetImpl();

// Provide a connection URL for future use
  jrs.setUrl("connection_url");

// Provide a SQL statement for future use 
  jrs.setCommand("SQL_statement");

// Create a connnection using DriverManager
// Execute the SQL statement
  jrs.execute();

Note that the name of method setUrl() is very confusing with another method setURL(), which sets a URL value to a parameter.

Note also that the connection URL and user information can also be provided through another constructor:

  JdbcRowSet jrs = new JdbcRowSetImpl("connection_url", 
    "user", "password");

To test connection method, I wrote the following tutorial program:

/**
 * OracleRowSetConnectionUrl.java
 * Copyright (c) 2007 by Dr. Herong Yang. All rights reserved.
 */
import java.sql.*;
public class OracleRowSetConnectionUrl {
  public static void main(String [] args) {
    try {

// Load the JDBC driver class. Needed for JDBC 3.0 drivers
      Class.forName("oracle.jdbc.OracleDriver") ;

// Get a new JdbcRowSet object with Run's implementation
      javax.sql.rowset.JdbcRowSet jrs 
        = new com.sun.rowset.JdbcRowSetImpl();

// Set the connection URL for the DriverManager
      jrs.setUrl(
        "jdbc:oracle:thin:Herong/TopSecret@//localhost:1521/XE");

// Set a SQL statement
      jrs.setCommand("SELECT 'Hello world!' FROM DUAL");

// Connect and run the statement
      jrs.execute();

// Get the result
      jrs.next();
      System.out.println("Result: "+jrs.getString(1));
      
// Close resource
      jrs.close();
    } catch (Exception e) {
      System.err.println("Exception: "+e.getMessage());
    }
  }
}

Make sure the Oracle server is running on the local machine, then run this program. The result confirms that the connection is working.

C:\>javac OracleRowSetConnectionUrl.java
OracleRowSetConnectionUrl.java:15: 
warning: com.sun.rowset.JdbcRowSetImpl is Sun proprietary API 
and may be removed in a future release
        = new com.sun.rowset.JdbcRowSetImpl();
                            ^
1 warning

C:\>java -cp .;\local\lib\ojdbc14.jar OracleRowSetConnectionUrl
Result: Hello world!

Notice that a warning message was given at the compilation time.

Also notice that class com.sun.rowset.JdbcRowSetImpl seems to be included in JDK 1.6 package, because I executed the program successfully without including rowset.jar file in the classpath.

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 Downloading and Installing JDK - Java SE

 Installing and Running Java DB - Derby

 Derby (Java DB) JDBC Driver

 Derby (Java DB) JDBC DataSource Objects

 Java DB (Derby) - DML Statements

 Java DB (Derby) - ResultSet Objects of Queries

 Java DB (Derby) - PreparedStatement

 MySQL Installation on Windows

 MySQL JDBC Driver (MySQL Connector/J)

 MySQL - PreparedStatement

 MySQL - Reference Implementation of JdbcRowSet

 MySQL - JBDC CallableStatement

 MySQL CLOB (Character Large Object) - TEXT

 MySQL BLOB (Binary Large Object) - BLOB

 Oracle Express Edition Installation on Windows

 Oracle JDBC Drivers

Oracle - Reference Implementation of JdbcRowSet

 Overview of RowSet Objects

 Installation of JdbcRowSet Reference Implementation

 Connecting JdbcRowSet to Database Servers

Connecting JdbcRowSet with a Connection URL

 Connecting JdbcRowSet with a Predefined Connection Object

 Connecting JdbcRowSet with a Predefined ResultSet Object

 Connecting JdbcRowSet with JNDI Directory Service

 JdbcRowSet Query Statement with Parameters

 Inserting Rows with JdbcRowSet Objects

 Oracle - PreparedStatement

 Oracle - JBDC CallableStatement

 Oracle CLOB (Character Large Object) - TEXT

 Oracle BLOB (Binary Large Object) - BLOB

 Microsoft SQL Server 2005 Express Edition

 Microsoft JDBC Driver for SQL Server - sqljdbc.jar

 Microsoft JDBC Driver - Query Statements and Result Sets

 Microsoft JDBC Driver - DatabaseMetaData Object

 Microsoft JDBC Driver - DDL Statements

 Microsoft JDBC Driver - DML Statements

 SQL Server - PreparedStatement

 SQL Server CLOB (Character Large Object) - TEXT

 SQL Server BLOB (Binary Large Object) - BLOB

 JDBC-ODBC Bridge Driver - sun.jdbc.odbc.JdbcOdbcDriver

 JDBC-ODBC Bridge Driver - Flat Text Files

 JDBC-ODBC Bridge Driver - MS Access

 JDBC-ODBC Bridge Driver - MS SQL Server

 Summary of JDBC Drivers and Database Servers

 Additional Tutorial Notes to Be Added

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2007
Connecting JdbcRowSet with a Connection URL