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

// Provide a SQL statement for future use 

// Create a connnection using DriverManager
// Execute the SQL statement

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:

 - Copyright (c) 2015,, All Rights Reserved.
import java.sql.*;
import javax.sql.rowset.RowSetProvider;
import javax.sql.rowset.JdbcRowSet;
public class OracleRowSetConnectionUrl {
  public static void main(String [] args) {
    try {

// Not needed anymore with JDK 1.8
//      Class.forName("oracle.jdbc.OracleDriver") ;

// RowSetFactory should be used now
//      JdbcRowSet jrs 
//        = new com.sun.rowset.JdbcRowSetImpl();
      JdbcRowSet jrs 
        = RowSetProvider.newFactory().createJdbcRowSet();

// Set the connection URL for the DriverManager

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

// Connect and run the statement

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

Make sure the Oracle server is running on the local machine, then run this program. The result with JDK 1.8, Oracle 11.2 and ojdbc6.jar confirms that the connection is working.


   -cp .;\local\lib\ojdbc6.jar

Result: Hello world!

But if you are JDK 1.6, Oracle 11.2 and ojdbc14.jar and use "new com.sun.rowset.JdbcRowSetImpl()" explicitly, you will get a compilation warning:

   -cp .;\local\lib\ojdbc14.jar 
warning: com.sun.rowset.JdbcRowSetImpl is Sun proprietary API 
and may be removed in a future release
        = new com.sun.rowset.JdbcRowSetImpl();
1 warning

   -cp .;\local\lib\ojdbc14.jar

Result: Hello world!

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.

Last update: 2015.

Table of Contents

 About This Book

 JDBC (Java Database Connectivity) Introduction

 JDK (Java SE) Installation

 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 - sqljdbc42.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

 Outdated Tutorials


 PDF Printing Version