tags:

views:

63

answers:

3

When you setup a URL in your jdbc properties like:

jdbc:derby://localhost:1527/vehicle;create=true

Does this mean all the data is being sent via HTTP on a specific port? (it seems so obviously)

+5  A: 

It has nothing to do with HTTP, no. The protocol used is specific to the database and JDBC driver, as is JDBC URL format. The only thing common to all JDBC URLs is the jdbc: prefix.

In this specific case, I'd say you have a Apache Derby JDBC URL, connecting to a server on localhost port 1527, database (or maybe user) name "vehicle", creating it if necessary.

Another example would be an Oracle JDBC URL format:

jdbc:oracle:<drivertype>:<username/password>@<database>

Very different to the Derby one, but specifying the same sort of information.

skaffman
A: 

The short answer is no. To understand why you need to understand the syntax of a URL. The basic syntax of a URI is

<url> ::= <scheme>:<scheme-specific-part>

where the is an identifier that says how to interpret the stuff after the colon. Most web URLs use the 'http' scheme; e.g.

http://www.example.com/somepage.html

though web browsers also understand other schemes such 'ftp', 'mailto' and so on.

But as you can see, a JDBC URL uses the 'jdbc' scheme; for example

jdbc:derby://localhost:1527/vehicle;create=true

In some cases (e.g. 'http' and 'ftp') the scheme has a correspond application protocol (e.g. HTTP or FTP respectively) that may be used for accessing content. (This assumes the URL actually resolves to something that is fetchable).

In other cases including the 'jdbc' scheme, the URL does not denote content, and does not necessarily even specify a protocol. In the JDBC case, the URL is actually specifying an end point location (and other details) for accessing a database. The stuff after the second colon is JDBC driver / RDBMS specific, both in syntax and in what it means. But it is highly unlikely that HTTP is involved, or that a web browser would know what to do with a JDBC URL.

Stephen C
A: 

Quoting the chapter 6 Database connections of the specification for the JDBC API (this is an old version but I find it more clear than more recent versions about JDBC URLs):

6.3 URLs

6.3.1 Goals for JDBC database naming

We need to provide a way of naming databases so that application writers can specify which database they wish to connect to.

We would like this JDBC naming mechanism to have the following properties:

  • Different drivers can use different schemes for naming databases. For example, a JDBC-ODBC bridge driver may support simple ODBC style data source names, whereas a network protocol driver may need to know additional information so it can discover which hostname and port to connect to.
  • If a user downloads an applet that wants to talk to a given database then we would like to be able to open a database connection without requiring the user to do any system administration chores. Thus for example, we want to avoid requiring an analogue of the human-administered ODBC data source tables on the client machines. This implies that it should be possible to encode any necessary connection information in the JDBC name.
  • We would like to allow a level of indirection in the JDBC name, so that the initial name may be resolved via some network naming system in order to locate the database. This will allow system administrators to avoid specifying particular hosts as part of the JDBC name. However, since there are a number of different network name services (such as NIS, DCE, etc.) we do not wish to mandate that any particular network nameserver is used.

6.3.2 URL syntax

Fortunately the World Wide Web has already standardized on a naming system that supports all of these properties. This is the Uniform Resource Locator (URL) mechanism. So we propose to use URLs for JDBC naming, and merely recommend some conventions for structuring JDBC URLs.

We recommend that JDBC URL's be structured as:

jdbc:<subprotocol>:<subname>

where a subprotocol names a particular kind of database connectivity mechanism that may be supported by one or more drivers. The contents and syntax of the subname will depend on the subprotocol.

If you are specifying a network address as part of your subname, we recommend following the standard URL naming convention of "//hostname:port/subsubname" for the subname. The subsubname can have arbitrary internal syntax.

To summarize:

  • The only thing in common between a JDBC URL and an HTTP URL is that both use the same standardized naming system: the Uniform Resource Locator (URL) mechanism (this is only a recommendation for JDBC1).

  • A JDBC URL is specific to a JDBC driver (different drivers for a same database will use different schemes). Refer to the documentation of the JDBC driver for the details (for example, when using Derby Network Server, have a look at Derby network client URL Format).

  • And no, the protocol used by a JDBC client to talk to a database server is not HTTP (it his a database specific protocol).


1 Actually, a JDBC URL may not be a real URI as mentioned in this note of the brand new JSR 221: JDBCTM 4.0 API Specification:

Note - A JDBC URL is not required to fully adhere to the URI syntax as defined in RFC 3986, Uniform Resource Identifier (URI): Generic Syntax.

Pascal Thivent